Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
ok, it's a simple case, i rendered a viewport3d object using RenderTargetBitmap @ resolution 600 * 600 @ 96 dpi, the problem is there are a big deference in quality between the view port and the saved image:

here are some code:

'rendering viewport3D to image
Dim viewportPlate As New RenderTargetBitmap(600, 600, 96 , 96 , PixelFormats.Pbgra32)
viewportPlate.Render(viewport3d)

'path to save
Dim path As String = imgSave
Dim fs As FileStream = New FileStream(path, FileMode.Create)

'encoding to PNG and saving
Dim encoder As BitmapEncoder = New PngBitmapEncoder()
encoder.Frames.Add(BitmapFrame.Create(viewportPlate))
encoder.Save(fs)




now i tried to render to a larger resolution then scale it down and it got better, but a new problem arises of the big render time (because of the software rendering) and the out of memory issues!!!

i'm using .net 4.0, is there a clear way to achieve a better anti-aliased solutions and render times, as it was for GDI+ which i consider is a bless besides WPF?????

any tips will be welcome :)
Posted
Comments
Sergey Alexandrovich Kryukov 20-Jun-11 9:48am    
Which one is poor quality?
--SA
bat3a 21-Jun-11 0:02am    
the saved one, her is a test, i captured the viewport3d using print screen
http://imageshack.us/photo/my-images/200/unledfy.jpg

1 solution

First of all, I must apologise because the extension method I'm going to show you is C#, but it shouldn't be too hard for you to convert it into VB.
C#
public static RenderTargetBitmap RenderBitmap(this Visual visualToRender)
{
  double scale = 600 / 96;
  RenderTargetBitmap bmp = new RenderTargetBitmap
  (
    (int)(scale * (visualToRender.ActualWidth + 1)),
    (int)(scale * (visualToRender.ActualHeight + 1)),
    scale * 96,
    scale * 96,
    PixelFormats.Default
  );
  bmp.Render(visualToRender);
  return bmp;
}

[Edit]The OP cannot use this code sample because he needs to scale the image again, and the process is slow.

The issue you have here is that RenderTargetBitmap does not use hardware rendering. It is entirely software rendered, hence the reason that it is prohibitively slow to render (this also counts to explain why the quality is reduced). If you could bear to introduce an external resource into your application, you could use SlimDX (a free DirectX wrapper) to render the viewport from your application.
 
Share this answer
 
v2
Comments
bat3a 22-Jun-11 9:57am    
thanks man i tried this solution and it works but i can't use this as the resulted image needs to be re-sized again-and when i do that it simply reverts back to the low quality-, another thing is the huge computing time, which renders this solution as not applicable, any more thoughts??
bat3a 22-Jun-11 10:08am    
so i just include the binaries and use some functions?, do you know how to find rendertargetbitmap equivalent function in slimDX, or have a tut about that, thanks.
Pete O'Hanlon 22-Jun-11 10:32am    
Off the top of my head, I don't know what you'd need to call in SlimDX. I do know that you can do this in C++ using:

extern IDirect3DDevice9* g_pd3dDevice;

void CaptureDevice(uint width, uint height)
{
IDirect3DSurface9* pSurface;
g_pd3dDevice->CreateOffscreenPlainSurface(
width, height,
D3DFMT_A8R8G8B8,
D3DPOOL_SCRATCH,
&pSurface,
NULL);
g_pd3dDevice->GetFrontBufferData(0, pSurface);
D3DXSaveSurfaceToFile("c:\\File.jpg",D3DXIFF_JPG,pSurface,NULL,NULL);
pSurface->Release();
}

So, the C# equivalent would need to use some combination of this. (Note that you have to get the Direct3D context to do this).
bat3a 22-Jun-11 10:57am    
is this using the slimDX, or directly from directX???
Pete O'Hanlon 22-Jun-11 11:10am    
That's a version of the C++ DirectX code that would have to be translated. The SlimDX version would be vastly simpler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900