Option Explicit Private m_lToken As Long Private Type GdiplusStartupInput GdiplusVersion As Long DebugEventCallback As Long SuppressBackgroundThread As Long SuppressExternalCodecs As Long End Type Private Declare Function GdiplusStartup Lib "gdiplus" ( _ token As Long, inputbuf As GdiplusStartupInput, _ Optional ByVal outputbuf As Long = 0) As Long Private Declare Function GdiplusShutdown Lib "gdiplus" ( _ ByVal token As Long) As Long Private Declare Function GdipCreateFromHDC Lib "gdiplus" ( _ ByVal hdc As Long, graphics As OLE_HANDLE) As Long Private Declare Function GdipGetImageWidth Lib "gdiplus" ( _ ByVal image As OLE_HANDLE, Width As Long) As Long Private Declare Function GdipGetImageHeight Lib "gdiplus" ( _ ByVal image As OLE_HANDLE, Height As Long) As Long Private Declare Function GdipDrawImageRectI Lib "gdiplus" ( _ ByVal graphics As OLE_HANDLE, ByVal image As Long, _ ByVal X As Long, ByVal Y As Long, _ ByVal Width As Long, ByVal Height As Long) As Long Private Declare Function GdipDeleteGraphics Lib "gdiplus" ( _ ByVal graphics As OLE_HANDLE) As Long Private Declare Function GdipDisposeImage Lib "gdiplus" ( _ ByVal image As OLE_HANDLE) As Long Private Declare Function GdipLoadImageFromStream Lib "gdiplus" _ (ByVal stm As Long, _ ByRef img As OLE_HANDLE) As Long Private Const GENERIC_READ As Long = &H80000000 Private Const GENERIC_WRITE As Long = &H40000000 Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ByRef ppstm As Any) As Long Private Const GMEM_MOVEABLE As Long = &H2& Private Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDest As Long, ByVal pSource As Long, ByVal dwLength As Long) Private ghMem As Long Private gImg As OLE_HANDLE Private glngWidth As Long Private glngHeight As Long Private Sub Form_Load() Dim gsi As GdiplusStartupInput gsi.GdiplusVersion = 1 Call GdiplusStartup(m_lToken, gsi) Picture1.AutoRedraw = True Command1.Caption = "ロード" Command2.Caption = "描画" Command3.Caption = "クリア" Command4.Caption = "アンロード" Command1.Enabled = True Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False End Sub Private Sub Command1_Click() Command1.Enabled = False Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Dim strFileName As String strFileName = Text1.Text Dim bin() As Byte Const adTypeBinary As Long = 1 Const adReadAll As Long = -1 With CreateObject("ADODB.Stream") .Type = adTypeBinary .Open .LoadFromFile strFileName bin = .Read(adReadAll) .Close End With Dim ret As Long Dim size As Long size = UBound(bin) + 1 Dim ptr As Long ghMem = GlobalAlloc(GMEM_MOVEABLE, size) ptr = GlobalLock(ghMem) RtlMoveMemory ptr, VarPtr(bin(0)), size ret = GlobalUnlock(ghMem) Dim stm As Object ret = CreateStreamOnHGlobal(ghMem, 1, stm) ret = GdipLoadImageFromStream(ObjPtr(stm), gImg) Set stm = Nothing ret = GdipGetImageWidth(gImg, glngWidth) ret = GdipGetImageHeight(gImg, glngHeight) End Sub Private Sub Command2_Click() Dim ret As Long Dim g As OLE_HANDLE ret = GdipCreateFromHDC(Picture1.hdc, g) ret = GdipDrawImageRectI(g, gImg, 0, 0, glngWidth, glngHeight) Picture1.Refresh ret = GdipDeleteGraphics(g) End Sub Private Sub Command3_Click() Picture1.Cls End Sub Private Sub Command4_Click() Command1.Enabled = True Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Dim ret As Long ret = GdipDisposeImage(gImg) End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If Command4.Enabled Then Command4.Value = True End If Call GdiplusShutdown(m_lToken) End Sub