LoginSignup
2
1

More than 5 years have passed since last update.

Twipをピクセルに変換する

Last updated at Posted at 2012-12-26

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
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1