VB.Net

Twipをピクセルに変換する

Twipをピクセルに変換する方法は以下の通りです。

Imports System.Runtime.CompilerServices

''X-coordinate
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)
  grph.ReleaseHdc(hdc)

  Return twipsX * pixelsX / 1440
End Function

''Y-X-coordinate
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)
  grph.ReleaseHdc(hdc)

  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