The MASM Forum

General => The Campus => Topic started by: caraveiro on March 22, 2013, 03:04:10 AM

Title: pixel ratio in logical units X / Y
Post by: caraveiro on March 22, 2013, 03:04:10 AM
Mean while on earth...


I'm trying to convert the X/Y ratio of a rectangle in pixels (MM_TEXT).
I want to draw in the window, for example, a perfect square and update the pixel size in a status bar.

I'm drawing with this:
Invoke SetMapMode, hdc, MM_ISOTROPIC
Invoke SetWindowExtEx,hdc, 32767, 32767, NULL
Invoke SetViewportExtEx,hdc,cxClient,-cyClient, NULL
Invoke SetViewportOrgEx,hdc,0,cyClient, NULL

But this only allow me to scaled axes while preserving equal logical units on the two axes, ergo a perfect square: x=100,Y=100


But once drawed, I lost how to convert MM_ISOTROPIC's units to MM_TEXT's units pixels.

So the status bar can show the real square unit: DLUs,Pixels, mm or inch

Any clues?

Best regards.
Title: Re: pixel ratio in logical units X / Y
Post by: qWord on March 22, 2013, 06:44:13 AM
If I'm not wrong, you can use the function LPtoDP() (http://msdn.microsoft.com/en-us/library/windows/desktop/dd145042%28v=vs.85%29.aspx) for the edge points of the rectangle to get the number of vertical and horizontal pixels.
Once having this numbers, you can use GetDeviceCaps(GetDC(0),LOGPIXELSX/Y) to calculate the values in inch and mm screen.
Title: Re: pixel ratio in logical units X / Y
Post by: caraveiro on March 22, 2013, 08:10:40 AM
Quote from: qWord on March 22, 2013, 06:44:13 AM
If I'm not wrong, you can use the function LPtoDP() (http://msdn.microsoft.com/en-us/library/windows/desktop/dd145042%28v=vs.85%29.aspx) for the edge points of the rectangle to get the number of vertical and horizontal pixels.
Once having this numbers, you can use GetDeviceCaps(GetDC(0),LOGPIXELSX/Y) to calculate the values in inch and mm screen.

Good tip, qWord, I'll use the GetDeviceCaps for the mm and inch convertion.

Also I'd found this reference:

Picture Aspect Ratio (http://msdn.microsoft.com/en-us/library/windows/desktop/bb530115(v=vs.85).aspx)
Pixel aspect ratio essentials (http://msdn.microsoft.com/en-us/library/cc294571.aspx)

Pixel Aspect Ratio for VIDEO: The PAR defines the shape of the pixels in an image. Square pixels have an aspect ratio of 1:1. Any other aspect ratio describes a non-square pixel. For example, NTSC television uses a 10:11 PAR. Assuming that you are presenting the video on a computer monitor, the display will have square pixels (1:1 PAR).

I just close to get the formula for the Pixel Aspect Ratio (PAR) of the Screen Resolution fo MM_TEXT mode.