I'm using some Images in my WPF applcation.
XAML:
<Image Name="ImageOrderedList"
Source="images/OrderedList.png"
ToolTip="Ordered List"
Margin="0,0,5,5"
Width="20"
Height="20"
SnapsToDevicePixels="True"
MouseUp="Image_MouseUp"
MouseEnter="Image_MouseEnter"
MouseLeave="Image_MouseLeave" />
But, they appear fuzzy:
Here's a zoomed-in, side-by-side comparison. An original is on the left:
Dead link - Blurry WPF Image Zoomed
Why doesn't that SnapsToDevicePixels="True"
line prevent this problem?
You may want to consider trying a new property available now in WPF4. Leave the
RenderOptions.BitmapScalingMode
to HighQuality or just don't declare it.NearestNeighbor worked for me except it led to jaggy bitmaps when zooming in on the application. It also didn't seem to fix any glitches where icons were sizing in weird ways.
On your root element (i.e. your main window) add this property:
UseLayoutRounding="True"
.A property previously only available in Silverlight has now fixed all Bitmap sizing woes. :)
Rather than using
SnapsToDevicePixels
, I instead usedRenderOptions.BitmapScalingMode
and they're now nice and crisp!XAML:
Here's how it now looks:
Crisp WPF Images http://img13.imageshack.us/img13/9926/crispwpfimages.gif
+1 for Zack Peterson
I'm using .Net 3.5 sp1 and it looks like the most simple solution for a large number of fuzzy images. It's not a big deal to specify RenderOptions in-place, but for 3rd-party components a style in app-level resource makes sense:
Worked nicely when AvalonDock started to render blurry icons.
Make sure you save the image in the same DPI as your WPF application is working in, some image formats have this info stored as metadata. I don't know if this solves the problem but I've hade some problems because of this where images resized to 100% got bigger or smaller than expected.
Might be something similar.
I have found that the RenderOptions.BitmapScalingMode="NearestNeighbor" does not work for me. I'm using Windows XP x32 with DirectX 9.0c. As the actual rendering for WPF is done with DirectX, this could have an effect. I do have anti-aliasing turned on for XP with the following registry entries:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Avalon.Graphics] "MaxMultisampleType"=dword:00000004 "EnableDebugControl"=dword:00000001
However, turning aa off with these settings has no effect on the images. I think this only effects 3D Viewports.
Finally, I found that the blurring occurs with the text of TextBlocks as well as images. And the blurring only happens for some text blocks and images, not all of them.
I believe this is a bug (or at least it was). Check out this Microsoft support e-mail exchange page for some ideas to fix it.