Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "GDIPlus_Simple.inc"
%IDC_Button = 500 : %IDC_Graphic = 501
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,320,340, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Load", 5,10,100,20
Control Add Graphic, hDlg, %IDC_Graphic,"", 10,30,300,300, %WS_Border
Graphic Attach hDlg, %IDC_Graphic : Graphic Color %Black, %White : Graphic Clear
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long, hDC As Dword
If Cb.Msg = %WM_Command and Cb.Ctl = %IDC_Button Then
Graphic Get DC to hDC
GDIPlus_LoadImage(hDC, "garyface.gif",w,h)
Graphic Redraw
Dialog Set Text hDlg, "Size: " + str$(w) + str$(h)
End If
End Function
Sub GDIPlus_LoadImage(hDC As DWord, fName As String, w as Long, h As Long)
Local pGraphics, pImage As Dword, strFileName As String
Local token As Dword, StartupInput As GdiplusStartupInput
'initialize GDIPlus
StartupInput.GdiplusVersion = 1
GdiplusStartup(token, StartupInput, ByVal %NULL)
'load/display image onto Graphic control
strFileName = UCode$(fName) 'image source file
GdipLoadImageFromFile(StrPtr(strFileName), pImage) 'pImage - image object
GdipCreateFromHDC(hDC, pGraphics) 'pGraphics - graphic object
GdipDrawImage(pGraphics, pImage, 0, 0) 'draw on graphic object
'get properties
GdipGetImageWidth(pImage,w)
GdipGetImageHeight(pImage, h)
'cleanup
If pImage Then GdipDisposeImage(pImage)
If pGraphics Then GdipDeleteGraphics(pGraphics)
'shut downn GDIPlus
GdiplusShutdown token ' Shutdown GDI+
End Sub
'gbs_00961
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm