How can I stretch bitmap in WPF without smoothing pixels
Finally found an answer, with some help from Experts Exchange. Class RenderOptions defines attached property BitmapScalingMode, which can be set to NearestNeighbor. So,
RenderOptions.SetBitmapScalingMode(imageDisplay, BitmapScalingMode.NearestNeighbor);
does the trick.
Zbynek Vrastil
Hate to put a dampener on things, but if NearestNeighbor
works like GDI+, then this will give you a limited success. As you increase magnification in areas of high contrast you might not get the desired results. In GDI+ you find blacks becoming blue, and whites becoming red - again I stress in areas of high contrast! If this isn't the case in WPF, think yourself lucky!
Perhaps a WCF developer could confirm that?
I've found that there are more options to consider, but I can only speak for the GDI+ Graphics
class, which might be useful to someone.
Graphics graph = e.Graphics;graph.InterpolationMode = InterpolationMode.NearestNeighbor;graph.CompositingQuality = CompositingQuality.AssumeLinear;graph.SmoothingMode = SmoothingMode.None;
This works for me. I think the SmoothingMode
is the trick. Hope this helps someone else out there.