Screen length and pixel length conversion

Source: Internet
Author: User

Recently I am going to create a WYSIWYG Graph Editor. I encountered a problem: If a straight line is drawn on the screen in pixels, how can I know the physical length of the editor on the screen? For example, suppose we create a simple single-document program pixertoinch using the wizard in vc6, And the ondraw function contains the following code:

Void cpixertoinchview: ondraw (CDC * PDC) <br/>{< br/> cpixertoinchdoc * pdoc = getdocument (); <br/> assert_valid (pdoc ); </P> <p> // todo: add draw code for native data here <br/> // draw a 96-pixel long horizontal line <br/> PDC-> moveTo (100,100 ); <br/> PDC-> lineto (196,100 ); </P> <p> // draw a 96-pixel long vertical line <br/> PDC-> moveTo (100,100 ); <br/> PDC-> lineto (100,196); <br/>}

So on the screen of my aoc915sw display, the actual measurement result is that the actual length of the horizontal line is close to 31mm, and the length of the vertical line is close to 33mm. Why does this result appear? I checked a lot of information and found that many materials are calculated using DPI, but the results are not consistent with my actual situation. After discussion with the netizen qiye, I finally found the correct calculation method, the following is an example for future reference.

To calculate the display length on the screen, you need to know the following parameters:

1. Maximum resolution of the monitor. The maximum resolution of a display can be found in the Technical Manual of this model. For example, for my aocsw915 display, the maximum resolution is 1440*900. Note: To distinguish the maximum resolution of the display from the maximum resolution of the video card, right-click "properties" on the desktop and choose "properties"> Settings ". The maximum resolution may be the maximum resolution of the video card, for example, if the video card model on my machine is Intel 82945g express chipset, its maximum resolution is 2048*1536.

To view the maximum resolution of a monitor directly, click "advanced" in "properties"> "Settings"> "Monitor ", select "Hide modes that cannot be displayed on the monitor", click OK, and return to the preceding dialog box. The maximum resolution displayed here is the maximum resolution of the monitor.

2. The actual resolution of the Windows system, that is, right-click "properties" on the desktop-> set the screen resolution value. Mine is 1280*768.

3. Check the technical parameters of the monitor. The period of aocsw915 is 0.285mm.

With the above parameters, we can calculate the actual length of a straight line in a certain direction.

Formula:

Screen length (in millimeters) = pixel length * Maximum resolution * point distance/current resolution

For example, for my code, the horizontal line length on the screen is

96*0.285*1440/1280 = 30.78mm

The screen length of the vertical line is

96*0.285*900/768 = 32.0625mm

It is consistent with my actual measurement results.

Summary: the actual length of the screen can be obtained by multiplying the pixel length by the current point distance, but the point distance marked by the display is the point distance at the maximum resolution (also known as the display in point-to-point mode) at this time, the vertex distance is the smallest. when the resolution is not the largest, it is equivalent to extending the vertex distance. At this time, a conversion coefficient is considered for the vertex distance, that is, the maximum resolution/current resolution. Therefore, the final formula is as follows:

Pixel length * (minimum point distance * Maximum resolution/actual resolution)

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.