Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Resizing Bitmap to increase image quality

$
0
0

I have an application that gets and saves a picture of an open window. Unfortunately, when the dimensions of the image and window match, the image quality is unacceptably low. I've increased the size the of the RenderTargetBitmap, which has increased the image quality, however, now the dimensions of the resulting image are too large for my purposes.

My question is this: Is there any way to resize the resulting RenderTargetBitmap to the original dimensions of the window? And is it possible to do this without a corresponding loss in image quality? Here's the code I have now.

public static RenderTargetBitmap GetReportImage(Grid view) { // Increased dimensions to increase image quality Size size = new Size(view.ActualWidth * 2, view.ActualHeight * 2 ); // The dimensions that I want to convert back to. _size = new Size(view.ActualWidth, view.ActualHeight); if (size.IsEmpty) return null; RenderTargetBitmap result = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96 , 96 , PixelFormats.Pbgra32); DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext context = drawingVisual.RenderOpen()) { context.DrawRectangle(new VisualBrush(view), null, new Rect(new Point(), size)); context.Close(); } result.Render(drawingVisual); // Can I resize result to _size.Width and _size.Height?


return result; }

Thanks in advance for any help.

Note: I tried calling this drawingVisual.Transform = new ScaleTransform(_size.Width, _size.Height); before rendering the result, but the jpg was just one solid color. 



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>