UareBugged
UareBugged

Reputation: 176

Images in WPF getting blurry

im trying to make something in WPF but i have one problem. Ive placed some elements to the window so in editor it looks thus:

enter image description here

In build it looks thus:

enter image description here

And if i place to element->

RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"

In build it look now:

enter image description here

I really dont know how to solve it so i will be really grateful that someone will help me

Upvotes: 1

Views: 1627

Answers (1)

TyCobb
TyCobb

Reputation: 9089

This is usually related to not having SnapsToDevicePixels set.

Pixel Snapping in WPF Applications

In your control or window, you can set it by doing

<MyControl SnapsToDevicePixels="True">

The WPF graphics system uses device-independent units to enable resolution and device independence. Each device independent pixel automatically scales with the system's dots per inch (dpi) setting. This provides WPF applications proper scaling for different dpi settings and makes the application automatically dpi-aware.

However, this dpi independence can create irregular edge rendering due to anti-aliasing. These artifacts, commonly seen as blurry, or semi-transparent, edges can occur when the location of an edge falls in the middle of a device pixel rather than between device pixels. To address this issue, WPF provides a way for object edges in a visual tree to snap, or become fixed, to device pixels through pixel snapping, eliminating the semi-transparent edges produced by anti-aliasing.

Pixel snapping is a means to suppress these visual artifacts by applying small offsets to the geometry of the visual to align the geometry to device pixels.

Upvotes: 4

Related Questions