Logical Millimeter vs Real Millimeter

H

Henry Wu

Hi, now that in .NET everything is on millimeter, I was wondering how
can one convert Pixel to Millimeter and any user's screen/monitor. I
saw the following code on how to convert pixel to millimeter. It's
done on pascal/delphi, but can be very easily read & converted to VB
..NET.

However my question is what is the difference between "real"
millimeters and "logical" millimeters?

The source of the code is in the following thread:
http://groups.google.com.ph/groups?...hl=en&ie=UTF-8&q=pixel+to+millimeters&spell=1

It's way back 1996, is it still correct & accurate?

Thanks,
Henry

======================================

procedure PixelsPerMM(canvas:TCanvas; var x,y:real);
procedure PixelsPerLogicalMM(canvas:TCanvas; var x,y:real);

implementation

procedure PixelsPerMM(canvas:TCanvas; var x,y:real);
var
h:HDC;
hres,vres,hsiz,vsiz:integer;
begin
h:=canvas.handle;
hres := GetDeviceCaps(h,HORZRES); {display width in pixels}
vres := GetDeviceCaps(h,VERTRES); {display height in pixels}
hsiz := GetDeviceCaps(h,HORZSIZE); {display width in mm}
vsiz := GetDeviceCaps(h,VERTSIZE); {display height in mm}
x := hres/hsiz;
y := vres/vsiz;
end;

procedure PixelsPerLogicalMM(canvas:TCanvas; var x,y:real);
var
h:hdc;
logpx,logpy:integer;
begin
h:=canvas.handle;
logpx := GetDeviceCaps(h,LOGPIXELSX); {pixels / logical x inch}
logpy := GetDeviceCaps(h,LOGPIXELSY); {pixels / logical y inch}
x := logpx / 25.4;
y := logpy / 25.4;
end;

end.

//ns
 
C

Cor Ligthert

Hi Henry,

Well saved

I hope this helps

Cor

\\\By Fergus Cooney
A Form's width is in pixels, as you've found. Each Form (actually Control)
has a drawing surface controlled by a Graphics object. This has a property
DpiX which is Dots-Per-Inch-Horizontal, and a corresponding DpiY.

try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)
//
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
\\\By Fergus Cooney
A Form's width is in pixels, as you've found. Each Form (actually Control)
has a drawing surface controlled by a Graphics object. This has a property
DpiX which is Dots-Per-Inch-Horizontal, and a corresponding DpiY.

try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)

\\\
g.Dispose()
///
 
H

Henry Wu

try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)
//

I see what your getting at, by using DPIX & DPIY, one can compute for
mm, inches etc.

There must be a typo here:
"Width (mm) " & SomeForm.Width & vbCrLf

SomeForm.Width returns pixels, as you said.
but I get what you mean. Thanks again!!! :)

Henry
 
S

Supra

u can't. metric already converted. to microsoft.net it had built in
function, i have read book by petzold .
regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top