Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have gray-scale raster image data from a camera. I want to display this data in my WPF application. I've used BitmapSource.Create(...) to create the image from the 'raw' data, and then displayed it in an Image control. Unfortunately, WPF interpolates the image, and the interpolation loses pixels, even when the display size and the image size are identical.

I've found an alternative: hosting a WinForms PictureBox control, which seems to render the bitmap without interpolation. This is workable but ugly.

Is there a WPF way to render a bitmap without the interpolation?
Posted

While it may not be pretty, you could try sizing your Image control to exactly match the size of the image placed in it.

This may prevent it from interpolating the image.
 
Share this answer
 
Comments
Gary R. Wheeler 17-Aug-10 18:00pm    
I've tried that; it didn't help. I can display the image at exactly the same number of pixels on the screen as in the bitmap, and they are still re-sampling it.
One other issue you face in WPF is that it checks the DPI of your image and scales it accordingly. This is a NIGHTMARE, there's nothing you can do about it, and nothing you can do to easily set the DPI of an image. Perhaps your DPI needs to match the screen DPI in order for no stretching to take place ?
 
Share this answer
 
Comments
Gary R. Wheeler 17-Aug-10 18:02pm    
I've managed to display the bitmap in the same number of pixels on the screen as in the image. It's still re-sampling the image.

Here's an example: I'm using an 8x8 test image, where the first row is black, the next row white, alternating for 8 rows. Instead of being pure black and white, each row is something like (41,41,41) and (209,209,209). They're resampling the image, even though they don't need to.

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