Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3891
  • Last Modified:

Convert Pixels to Twips

I am trying to convert pixels to twips.  I know about TwipsPerPixelX, but it only seems to work with Screen.TwipsPerPixelX.  Is there a built in function that does this or does someone have a conversion formula?
0
joesmow
Asked:
joesmow
1 Solution
 
bruintjeCommented:
Hi joesmow,

From the Access Developers Handbook

===================================
http://www.mcwtech.com
Stop by http://www.developershandbook.com   
if you have any of the Developer's Handbooks
co-authored by MCW Technologies folks.
Updates, info, and registration available.

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

Private Declare Function GetDC _
 Lib "user32" _
 (ByVal hWnd As Long) As Long

Private Declare Function ReleaseDC _
 Lib "user32" _
 (ByVal hWnd As Long, ByVal hdc As Long) As Long

Private Declare Function GetSystemMetrics _
 Lib "user32" _
 (ByVal nIndex As Long) As Long
 
Private Declare Function GetDeviceCaps _
 Lib "gdi32" _
 (ByVal hdc As Long, ByVal nIndex As Long) As Long

Private Type POINTAPI
    x As Long
    y As Long
End Type

' These give the size of the whole screen.
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

' These give the usable size of the screen.
Private Const SM_CXFULLSCREEN = 16
Private Const SM_CYFULLSCREEN = 17

Private Const LOGPIXELSX = 88        '  Logical pixels/inch in X
Private Const LOGPIXELSY = 90        '  Logical pixels/inch in Y
Private Const adhcTwipsPerInch = 1440

Private mptCurrentDPI As POINTAPI
Private mptTwipsPerPixel As POINTAPI
Private mptCurrentScreen As POINTAPI

Public Sub GetScreenInfo()
    ' Get the information context you need to find
    ' the screen info.
    ' This procedure fills in the module variables:
    ' mptCurrentScreen
    ' mptCurrentDPI
    ' mptTwipsPerPixel
   
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert (Sybex)
    ' Copyright 1999.  All rights reserved.
   
    Const HWND_DESKTOP = 0
    Dim lngDC As Long
   
    lngDC = GetDC(HWND_DESKTOP)

    ' If the call to GetDC didn't fail (and it had
    ' better not, or things are really busted),
    ' then get the info.
   
    If lngDC <> 0 Then
        ' Find the number of pixels in both directions on the
        ' screen, (640x480, 800x600, 1024x768, 1280x1024?).
        mptCurrentScreen.x = GetSystemMetrics(SM_CXSCREEN)
        mptCurrentScreen.y = GetSystemMetrics(SM_CYSCREEN)
       
        ' Get the pixels/inch ratio, as well.
        mptCurrentDPI.x = GetDeviceCaps(lngDC, LOGPIXELSX)
        mptCurrentDPI.y = GetDeviceCaps(lngDC, LOGPIXELSY)
       
        mptTwipsPerPixel.x = adhcTwipsPerInch / mptCurrentDPI.x
        mptTwipsPerPixel.y = adhcTwipsPerInch / mptCurrentDPI.y

        ' Release the information context.
        Call ReleaseDC(HWND_DESKTOP, lngDC)
    End If
End Sub

HTH:O)Bruintje
0
 
Richie_SimonettiCommented:
ypu could use multiply pixel per twips:

pixel * 15 = twips
0
 
Jeremy_DCommented:
joesmow: What exactly is the problem in using the TwipsPerPixel properties of the Screen object?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jeremy_DCommented:
bruintje: that seems like an incredible elaborate way to do this:

TwipsX = PixelsX * Screen.TwipsPerPixelX
TwipsY = PixelsY * Screen.TwipsPerPixelY


0
 
Jeremy_DCommented:
Richie: Assuming 15 twips per pixel will bring you into problems. This value is not the same for all display devices. I seem to remember that for instance the on-board graphics of the Intel 810 chipset motherboards work with 14 twips per pixel. Might have been another graphics device, but you get my drift, 15 is not a fixed number.
0
 
IBRownCommented:
Richie: There are only 15 twips per pixel when working on the screen in 'small fonts'. Change to 'large fonts' and the value is something like 12.

Joesmow: There is a Printer.TwipsPerPixelX and Printer.TwipsPerPixelY. What is the problem you are having? What is it that you are trying to do?
0
 
Richie_SimonettiCommented:
Yep, i know. Just a cheap comment ;)
0
 
joesmowAuthor Commented:
Thanks.  I just misunderstood how Screen.TwipsPerPixelX works.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now