470,810 Members | 1,978 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Logical Millimeter vs Real Millimeter

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?h...rs%26spell%3D1

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
Nov 20 '05 #1
5 2565
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)
//
Nov 20 '05 #2
* "Cor Ligthert" <no**********@planet.nl> scripsit:
\\\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()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
> * "Cor Ligthert" <no**********@planet.nl> scripsit:
\\\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()
///

That Fergus even now he get a message from you. I changed it in his code, I
think he will agree that.

:-)

Cor
Nov 20 '05 #4
> 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
Nov 20 '05 #5
u can't. metric already converted. to microsoft.net it had built in
function, i have read book by petzold .
regards

Henry Wu wrote:
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?h...rs%26spell%3D1

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


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by sam | last post: by
80 posts views Thread by Christopher Benson-Manica | last post: by
8 posts views Thread by FuzzyLogik | last post: by
9 posts views Thread by marko | last post: by
reply views Thread by Roald | last post: by
2 posts views Thread by dbtwo | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.