Date: 02-16-2022
Return to Index
created by gbSnippets
'... this snippet is in work
'load/display image onto Graphic control
strFileName = UCode$("garyface.gif") '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
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "GDIPlus_Simple.inc"
#Resource "gbsnippets.pbr"
%IDC_Graphic = 501
%IDC_ButtonBMP = 502
%IDC_ButtonGIF = 503
%IDC_ButtonJPG = 504
Global hDlg, hDC as Dword
Function PBMain() As Long
'initialize GDIPlus
Local token As Dword, StartupInput As GdiplusStartupInput
StartupInput.GdiplusVersion = 1
GdiplusStartup(token, StartupInput, ByVal %NULL)
'normal app stuff
Dialog New Pixels, 0, "Test Code",300,300,320,340, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_ButtonBMP,"Save As BMP", 5,10,100,20
Control Add Button, hDlg, %IDC_ButtonGIF,"Save As GIF", 5,35,100,20
Control Add Button, hDlg, %IDC_ButtonJPG,"Save As JPG", 5,60,100,20
Control Add Graphic, hDlg, %IDC_Graphic,"", 10,90,200,200, %WS_Border
Graphic Attach hDlg, %IDC_Graphic : Graphic Color %Black, %White : Graphic Clear
Graphic Render "cowgirl", (0,0)-(100,100) 'same size (could resize)
Graphic Get DC to hDC
Dialog Show Modal hDlg Call DlgProc
'shut downn GDIPlus
GdiplusShutdown token ' Shutdown GDI+
End Function
CallBack Function DlgProc() As Long
Dim iStart As Long, iEnd As Long, Result As String
Select Case Cb.Msg
Case %WM_InitDialog
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_ButtonBMP : GDIPlus_SaveImage("image/bmp", "test.bmp")
Case %IDC_ButtonGIF : GDIPlus_SaveImage("image/gif", "test.gif")
Case %IDC_ButtonJPG : GDIPlus_SaveImage("image/jpeg", "test.jpg")
End Select
Case %WM_Destroy
End Select
End Function
Sub GDIPlus_SaveImage(sMimeType As String, fName As String)
Local s as String, sEncoderClsid As GUID, pImage as Dword
s = GDIPLusGetEncoderClsid(sMimeType)
sEncoderClsid = Guid$(s)
fName = UCode$(fName) 'image source file
GdipCreateBitmapFromHBITMAP
GdipSaveImageToFile(pImage,StrPtr(fName),sEncoderClsid, ByVal %Null)
'cleanup
If pImage Then GdipDisposeImage(pImage)
If pGraphics Then GdipDeleteGraphics(pGraphics)
End Sub
'gbs_00962
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm