#277 – Images May Have Embedded DpiX and DpiY Information

Even when you specify Stretch=None for an Image control, you may notice that the image does not appear at the expected number of pixels wide/high.  This can happen if the image’s resolution (DPI) doesn’t match your current system DPI.

An image file (e.g. .png or .jpg) contains an image that is a certain number of pixels wide/high.  An image file may also contain embedded DpiX and DpiY (resolution) information.  This resolution information is not present in all image files.

WPF uses this resolution information to calculate the image size in WPF Units as:

  • Width (in WPF Units) = (96 * ImageWidth) / ImageHorizontalDPI
  • Height (in WPF Units) = (96 * ImageHeight) / ImageVerticalDPI

If there is no resolution information in the file, WPF defaults to 96 dpi.

WPF then calculates the image size in pixels as:

  • Width (pixels) = Width (WPF Units) * (SystemDPI / 96)
  • Height (pixels) = Height (WPF Units) * (SystemDPI / 96)



About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: