简体   繁体   中英

Image Saving Scaling Issues C# WPF

I'm capturing an image from a webcam in a C# WPF application and saving it to a JPEG by converting a System.Windows.Controls.Image object into a bitmap through the RenderTargetBitmap object.

When I go so save the returned object from my conversion function, it saves successfully moves the image down and to the left of the screen. It's almost like it saves the image but adds a ton of padding to it causing the actual image to move out of view.

The code I think might be causing these issues is below. Initially I thought I was having issues with DPI and height/width of the saved image, but realized that my issue was the padding I mentioned above.

var scale = 1.5;
RenderTargetBitmap rtb2 = new RenderTargetBitmap((int)(scale * imageControl.Source.Width), (int)(scale * imageControl.Source.Height), 96, 96, PixelFormats.Default);

Any help is very much appreciated.

RenderTargetBitmap already does the scaling. So by multiplying the imageControl.Source.Width and Height with your scale you are rescaling the already scaled image and therefore the image appears padded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM