View Full Version : Hi! Metrics (urgh)
SMurf
10-27-2001, 07:11 AM
Hi,
How do I convert himetric measurements to pixels WITHOUT the use of a control or form (this is in a module)?
Squirm
10-27-2001, 07:13 AM
Im not sure what you mean by himetrics, but.....
You can convert twips to pixels by dividing the twips by the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY depending on which dimension you are using...
SMurf
10-27-2001, 07:19 AM
You don't know what himetrics are?
Load a picture into a PictureBox object, then look at the Width and Height properties of its Picture object.
Marvel at the massive and completely useless numbers.
Squirm
10-27-2001, 07:27 AM
Thanks for that, I never noticed there was a difference between the two numbers before. However, if you could tell me how you convert them to pixels using a form or control I might be able to shed some light onto how to convert WITHOUT a form/control.
SMurf
10-27-2001, 07:31 AM
Apparently you can use the ScaleX and ScaleY methods of the form, specifying:-
.ScaleX [width in himetrics], vbHimetric, vbPixels
.ScaleY [height in himetrics], vbHimetric, vbPixels
Squirm
10-27-2001, 07:39 AM
I came up with this, it works fine to me. I cannot tell whether the himetrics is system specific or not..... tell me if this doesnt work:
<pre>Private Function Himetrics2PixelsX(lWidth As Long) As Long
Himetrics2PixelsX = CLng(lWidth / 26.2222222222222)
End Function
Private Function Himetrics2PixelsY(lHeight As Long) As Long
Himetrics2PixelsY = CLng(lHeight / 25.8421052631579)
End Function</pre>
SMurf
10-27-2001, 07:46 AM
Nah, that doesn't give me accurate values:-
Himetrics2PixelsX(15436) = 588.661016949153 (should be 580)
Himetrics2PixelsY(14817) = 573.366598778003 (should be 560)
I see your logic, on my system (if its tied to screen resolution, mine is 1280x1024) the divisions would be:-
26.613793103448275862068965517241 and 26.458928571428571428571428571429
for X and Y respectively.
Squirm
10-27-2001, 07:46 AM
DOH! This is what I should have put:
<pre>Private Function Himetrics2Pixels(lHeight As Long) As Long
Himetrics2Pixels = CLng(lHeight / 26.457399103139)
End Function</pre>
A universal converter.
SMurf
10-27-2001, 07:53 AM
Well, that works quite nicely (with integer truncation), although playing with large double-precision numbers in VB's always gonna make me queasy. Be nice if there was a simple global scaling system (ScaleX and ScaleY for the Screen object, for instance), but this'll do. Thanks very much.
BillSoo
10-27-2001, 01:37 PM
A himetric unit is 0.01 millimetre, or 1000 per cm. There are 567 twips per cm (1440 per inch). The number of twips per pixel depends on your screen resolution, but usually it's around 15. So to convert himetric to pixels would be:
pix = (hm /1000 ) * 567/twipsperpixelXorY
or around 0.0378
Powered by: vBulletin v3.8.6