I recently handled a problem about DPI. I think it's interesting to share it with you. First, let's clarify several concepts:
- DPI:Dots per inch, the number of points per inch. We often say that the mouse DPI refers to the number of points that move the mouse 1 inch away from the slippery point; print DPI, the number of points that are printed per inch in length; scan DPI, how many points are scanned per inch. (For more information, see Baidu encyclopedia http://baike.baidu.com/view/49853.htm)
- Pixels:Pixel, short for picute and element. Pixels can be simply understood as dots in DPI. For example, the resolution of a display is 1024 pixels * 768 pixels, that is, the display can display 1024 vertices (pixels) horizontally and 768 vertices (pixels) vertically ). Some monitors closely arrange each display point, and more points can be arranged within the length of 1 inch. Some display points are relatively loose and less, therefore, there is no direct relationship between pixels and inches. (For more information, see Baidu encyclopedia http://baike.baidu.com/view/575.htm)
- Resolution:For the above example, what does it mean to adjust the resolution of the monitor? A display has a natural resolution, which is the maximum performance of the display. For example, if the display's natural resolution is 1600*1200, the resolution with a length less than 1600 and a width less than 1200 can be displayed, 1900*1300 resolution will not work.
- Set custom text size (DPI):I personally think that this DPI is not the same as the above DPI. I don't know why Microsoft also called this DPI. First, the physical DPI of the display device is unlikely to change. Secondly, friends found that the default DPI value is 96, that is, 1 inch printing 96 pixels, when we adjust DPI to 125, 1 inch prints 125 points. Most of our application interfaces are designed according to 96 DPI. After 1 inch DPI, the length of 1 inch is no longer. It should be a little smaller. In fact, it is not small, but it increases, I don't think it is the same as the above DPI. At least it is not a physical DPI change.
Then think about it. It is similar to XP's magnifier function and the prompt is "make it easier to read what is on your screen". So, I think it should mean this, in the past, 1 inch was printed at 96 o'clock, and the distance between the two dots remained unchanged. The distance between the two dots was printed at 125 o'clock, which is more than 1 inch, you can see it clearly.
Well, let's get down to the point: WPF is handled like this. No matter what DPI the hardware is or what DPI the operating system is, it is calculated based on 96 DPI. That is to say, A pixel in WPF is equal to 1/96 inch. As a result, the problem seems to have come out. During the design, we all performed under 96 DPI. After arriving at the customer's machine, the strange problem emerged as follows:
- Under 96 DPI, the display resolution is 1024*768, and the interface width of the application is 900. When it reaches DPI, the interface is dumpfounded and cropped, this is especially true. What should we do? Set minheight and minwidth for window to make these two values equal to height and width. In high DPI windows, he found that he could not display all the width of the interface and tried his best to display the cropped content, when minheight is set, it is equivalent to force display. It must display at least this size.
- In high DPI, application a interacts with other application B, and B tells a: it is displayed at the (600,500) position, that is, the command. left = 600,. top = 500. The size of B is calculated based on high DPI (for example, 125) and has been enlarged. A is a WPF program and only knows 96 DPI. Therefore, a cannot be honestly displayed according to this point, but needs to be converted to. left = 600/(125/96), after WPF repainting,
Windows carefully zoomed in to meet B's requirements.
- In high DPI, the width and height settings of the WPF application are similar to the left and top settings in 2. You need to perform a conversion. If the requirement is that the width and height are automatically enlarged with DPI, you don't have to deal with it like this.
- The font problem, DPI in win7, is designed for a larger font and easier to see clearly. If the DPI is high, you have to deal with multiple languages. Some languages have a very long translation time, Large fonts, and limited sizes. In this case, you may need to change the font size as appropriate.
The above is my opinion. If not, please correct me.