Working Pixel to Twips conversion?
Working Pixel to Twips conversion?
Ive been looking at code all day long, and have not found a real working conversion code for converting Pixel to Twips...
Some people claim PIXELS * 15, or PIXELS * 15.5, however that is 100% fake. Try the above with a 1440x900x32 resolution, the result is always wrong...
Anybody have a real conversion code for this?
Some people claim PIXELS * 15, or PIXELS * 15.5, however that is 100% fake. Try the above with a 1440x900x32 resolution, the result is always wrong...
Anybody have a real conversion code for this?
Re: Working Pixel to Twips conversion?
> Some people claim PIXELS * 15
That's how I knew it. A Visual Basic form that uses twips for its form size is
the above equation, and that's a fact. I never knew twips to be anything else.
That's how I knew it. A Visual Basic form that uses twips for its form size is
the above equation, and that's a fact. I never knew twips to be anything else.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
> Not a fact
Sorry, my mistake: I meant that twips/15 = pixels (not *15). I opened VB
and made a form whose width is 6300 twips, and height is 5100 twips. Divide
these by 15 and you get 420 pixels wide and 340 pixels high. If you check
this form with any window viewer, these pixels dimensions are correct.
So, for all intents and purposes, twips/15 = pixels (in my experience/tests).
UPDATE: Sorry (again) -- I just realised you're trying to convert pixels to
twips, not twips to pixels.
I've never had to do that, so I don't know.
Sorry, my mistake: I meant that twips/15 = pixels (not *15). I opened VB
and made a form whose width is 6300 twips, and height is 5100 twips. Divide
these by 15 and you get 420 pixels wide and 340 pixels high. If you check
this form with any window viewer, these pixels dimensions are correct.
So, for all intents and purposes, twips/15 = pixels (in my experience/tests).
UPDATE: Sorry (again) -- I just realised you're trying to convert pixels to
twips, not twips to pixels.

-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Here are two functions to get the current Twips per pixel:
I hope my 1337 pr0gr4mm1ng skillz helped ^_^
Code: Select all
#LOGPIXELSX=88
#LOGPIXELSY=90
Procedure GetTwipsPerPixelX()
hDC=GetDC_(GetDesktopWindow_())
TwipsPerPixelX=1440/GetDeviceCaps_(hDC,#LOGPIXELSX)
ReleaseDC_(GetDesktopWindow_(),hDC)
ProcedureReturn TwipsPerPixelX
EndProcedure
Procedure GetTwipsPerPixelY()
hDC=GetDC_(GetDesktopWindow_())
TwipsPerPixelY=1440/GetDeviceCaps_(hDC,#LOGPIXELSY)
ReleaseDC_(GetDesktopWindow_(),hDC)
ProcedureReturn TwipsPerPixelY
EndProcedure
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact: