3
votes
  1. I set my screen to 72 DPI and designed a small png image that is 100x100 @ 72 DPI. Which means 72 pixels represents 1 inch.
  2. Now I changed my screen to 120 DPI and designed the same graphic png image with 100x100 @ 120 DPI. Which means 120 pixels represents 1 inch.
  3. Again I changed my screen to 96 DPI. Which means 96 pixels represents 1 inch. Then Created a WPF application and added the two images (step 1 and step 2) - I have set the Stretch Mode to None

Not sure if I have understood the concept properly, I expected the 72 dpi image to look smaller at 96 dpi because if 72 pixels represented 1 inch for that image, then in the new configuration 96 pixels represents 1 inch. And therefore I expected the 72 dpi image to look smaller. But is not the case. Infact, it was just he opposite. The 72 dpi image look bigger @ 96 dpi. Why? Is it like WPF will always default to 96 dpi when it comes to images?

enter image description here

Update Why is that, even at 120 dpi (setting system dpi to 120), only 96 dpi image fits 200x200 box perfectly? enter image description here

2
Can you show the XAML behind that image please?Gusdor
I guess I understood the send part of the issue, "Why is that, even at 120 dpi (setting system dpi to 120), only 96 dpi image fits 200x200 box perfectly?" I am trying to compare the image size against the border of the grid lines, while the grid control itself is getting scaled by WPF! If I take a screenshot and compare the pixels occupied, @ 120dpi, the 120dpi image measures 200x200 in the second column as expected! Correct me if i am wrong.sudarsanyes
pastebin blocked in my office. can you put it in the question please.Gusdor

2 Answers

2
votes

You are making some odd assumptions about the nature of device independent nature of WPF's graphical units.

A device independent pixel in wpf world is worth 1/96th of an inch regardless of the screen settings. This is why only the 96 dpi experiment is correct.

Secondly, your monitors native dpi has an impact

The second scale factor, the “DPI setting”, is what we will vary in our tests. WPF doesn’t independently know what your monitor’s actual physical DPI value is. Instead WPF uses the current setting of this second scale factor the “DPI setting”. If the “DPI setting” does not match the true physical DPI, then WPF’s “resolution independence” will appear to break — although it really doesn’t.

http://www.wpflearningexperience.com/?p=41

1
votes

An image that has 72 dots per inch (DPI) will have 72 dots per inch, whereas an image that has 120 DPI will have 120 per inch. Therefore, if we are displaying an image that is an inch by an inch, each side will have 72 dots for the 72 DPI image and 120 dots for the 120 DPI image.

Therefore, each dot in the 72 DPI image is larger than each dot in the 120 image, so the whole 72 DPI image is larger than the 120 DPI image.

For further reading, you might like to view the DPI setting and resolution of WPF application page on the Mindfire Solutions website.