Does WPF really have nothing to do with resolution ?, WPF Unit Resolution

Source: Internet
Author: User

Does WPF really have nothing to do with resolution ?, WPF Unit Resolution

Reprinted from http://www.cnblogs.com/helloj2ee/archive/2009/04/21/1440709.htm

From the date of release, WPF has always regarded "resolution independence" as its highlight, it is claimed that the user interface created using WPF can be displayed on a lightweight Ultra-Mobile PC screen and on a 50 inch TV. Microsoft claims that WPF has the "Resolution independence" feature mainly because the coordinate units of WPF are designed to be 1/96 inch as a logical pixel unit rather than the device-related pixel unit.

However, Microsoft has not explained the "Resolution independence" feature of WPF, which leads to many misunderstandings.

Misunderstanding

Change the resolution settings of the display. The size of the same WPF user interface and the drawing will not change.

This can be proved wrong by a very simple experiment. Create a new WPF application window with a height of 400 DIUs (DIU: Device independent unit, Device-independent unit) and a width of 600 DIUs, let the window run in an environment with the resolution set to 1280*1024 and 800*600 respectively, as shown in, the sizes of the two windows are obviously different.

Figure 1 resolution 1280*1024 on the left and 800*600 on the right

 

Misunderstanding 2

 

Change the DPI settings of the display. The size of the same WPF user interface and the drawing will not change.

The displayed DPI settings can be called in the XP system by right-clicking -- properties -- settings tab -- advanced, as shown in:

 

Figure 2 display attribute DPI settings

This can also be proved wrong in the same way. The windows with a height of 400 DIUs [1] and a width of DIUs run in the 96DPI and 192DPI setting environments respectively. We can also see that the size of the window is different.

Figure 3 96 DPI on the left and 192 DPI on the right

 

Misunderstanding 3

On different screens, if DPI settings are the same, the size of the same WPF user interface and the drawing will not change.

In this place, it is necessary to explain the DPI settings on the screen. The DPI setting refers to the number of pixels per inch on the screen. For example, the current setting is 96 DPI, that is, 96 pixels on the screen is 1 inch. Generally, Windows XP has three options: normal size (96 DPI), large size (120 DPI), and custom size. Since the coordinate unit of WPF is 1/96 inch as a logical pixel unit, we have reason to believe that if the DPI settings of the two monitors are the same, the size of the same WPF user interface and the drawing will not change. Unfortunately, this conclusion is still a mistake.

CalvinP. Schrotenboer also uses an experiment to prove this is an error. The actual screen width and height (in pixel units) of the desktop LCD display are 1600x1200, which must be distinguished from the normal resolution settings, this is the maximum resolution or physical resolution of the display device, that is, the display screen is 1600x1200 pixels physically. In English, this resolution is also known as "native resolution (native resolution )". Because the physical sizes of the two screens are different, the actual physical DPI can be obtained through the calculation formula in the table. There is no connection between the actual physical DPI and the DPI settings of the operating system.

Table 1 experiment environment

 

Lab Environment

System 1

System 2

Display type

Desktop LCD display

Notebook LCD display

Screen width and height

(Pixel unit)

1600x1200

1400x1050

Screen width and height

(In inches)

17.0x12.75

12.0x9.0

Actual physical DPI

Portrait: 1600/17 .0 = 94 DPI

Horizontal: 1200/12 .75 = 94 DPI

Portrait: 1400/12 = 117 DPI

Horizontal: 1050/9 = 117 DPI

DPI settings of the Operating System

96 DPI

96 DPI

 

Run the same WPF Application in two different systems. The program draws a straight line with a length of 384DIUs and converts it to an inch, that is, 384/96 = 4 inch. The actual size of the result in the two systems is shown in:

 

Figure 4 Actual size: 4.08 inch; actual size: 3.28 inch (CalvinP. Schrotenboer, 2006)

 

Where is the problem?

In fact, we can see some clues from table 1, because the actual physical DPI is inconsistent with the DPI set by the operating system. WPF cannot know the actual physical DPI of the current device. On the contrary, the DPI value of the operating system is obtained through the API function of the operating system, which is simply considered as the actual physical DPI value. For example, on a desktop LCD display, the actual size of a physical pixel is 1/94 inch. Since the operating system is set to 96 DPI, WPF stubbornly thinks that the actual pixel is 1/96 inch, therefore, the length of a line segment is 1/94*384 = 4.08 inch. The actual physical pixel size of a notebook display is 1/117 inch, so the line segment length is 1/117*384 = 3.28 inch. This value exactly matches our measurement results.

We have reason to speculate that if the DPI of the operating system is set to the actual physical DPI, the true "Resolution independence" can be achieved ", the line segments displayed on two different monitors are 4 inch in length, as shown in Figure 5:

Figure 5 the left figure shows the desktop LCD display, the DPI is set to 94, the right figure shows the notebook display, and the DPI is set to 117.

The resolution of WPF has nothing to do with so far. So we have to discuss another question: is there such a problem on the display? Is there such a problem on the printer? It can still be proved by an experiment. Draw a straight line of 4 inch and print the lines with DPI set to 96 DPI and 120DPI respectively. As shown in:

Figure 6 the result is printed at 120DPI for the system, and the result is printed at 96 DPI for the system.

 

Conclusion

Through the analysis of the above experiments, we can draw two conclusions:

(1) WPF can achieve "Resolution independence" when printing, that is, the same WPF user interface and the drawing size are consistent on any printer;

(2) When the physical size of the display is consistent with the DPI set by the system, WPF can achieve "Resolution independence" on the display ", that is to say, the size of the same WPF user interface and the drawing image are consistent on any display (the physical size of the actual pixel is consistent with the DPI set by the system. Otherwise, it cannot be guaranteed.

More discussions

The definition of "Resolution independence" is indeed easy to misunderstand because Microsoft has not discussed much about it. In most detail, the article "Resolution independence" in WPF Is a blog post "Is WPF Really Resolution Independent?" by CalvinP. Schrotenboer ?". Of course, Charles Peztold also discussed this issue in his blog. In addition, at Microsoft's forum, stefanw, Charles Peztold and others made in-depth discussions on "Resolution independence" and "device independence" of WPF.

Users can ignore this, but for a programmer, especially a programmer who is working on a drawing program, especially a drawing programmer who still needs to print the output, you must be clear about the details. It is also a pleasure to understand the details.

References

[1] CalvinP. Schrotenboer (2006), Is WPF Really Resolution Independent? Http://www.wpflearningexperience.com /? P = 41

[2] Stephen W, Charles Peztold, etc (2007), Resolution Independence ?, Http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/33bdb15c-a04c-4c17-85e1-6c2802f80b90

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.