By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Logical Millimeter vs Real Millimeter

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
* "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

P: n/a
> * "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

P: n/a
> 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

P: n/a
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.