More than 1 year has passed since last update.


Imports System.Runtime.CompilerServices

Public Function Twips2PixelsX(ByRef grph As Graphics, ByVal twipsX As Integer) As Double
  Dim LOGPIXELSX As Int32 = 88
  Dim hdc As IntPtr = grph.GetHdc
  Dim pixelsX As Int32 = GetDeviceCaps(hdc, LOGPIXELSX)

  Return twipsX * pixelsX / 1440
End Function

Public Function Twips2PixelsY(ByRef grph As Graphics, ByVal twipsY As Integer) As Double
  Dim LOGPIXELSY As Int32 = 90
  Dim hdc As IntPtr = grph.GetHdc
  Dim pixelsY As Int32 = GetDeviceCaps(hdc, LOGPIXELSY)

  Return twipsY * pixelsY / 1440
End Function

''Get device information
<System.Runtime.InteropServices.DllImport("gdi32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto)> _
Private Function GetDeviceCaps(ByVal Phdc As IntPtr, ByVal cIndex As Int32) As Int32
End Function
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.