Date: 02-16-2022
Return to Index
created by gbSnippets
'... this snippet is in work
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Debug Error On 'catch array/pointer errors
#Debug Display On 'display untrapped errors
#Include "Gdiplus_simple.inc"
#Include "Gdiputils.inc"
#Resource "gbsnippets.pbr"
%IDC_Graphic = 200 : %IDC_ButtonSave = 201 : %IDC_ButtonLoad = 202
Global hDlg, hGraphicDC, hBMP As Dword
Function PBMain() As Long
'initialize GDIPlus
Local token As Dword, StartupInput As GdiplusStartupInput
StartupInput.GdiplusVersion = 1
GdiplusStartup(token, StartupInput, ByVal %NULL)
Dialog New Pixels, 0, "Test Code",300,300,350,350, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_ButtonSave,"Save", 10,10,100,20
Control Add Button, hDlg, %IDC_ButtonLoad,"Load", 130,10,100,20
Control Add Graphic, hDlg, %IDC_Graphic,"", 20,40,300,300
Graphic Attach hDlg, %IDC_Graphic
Graphic Render "ruler.bmp", (0,0)-(299,299)
Control Handle hDlg, %IDC_Graphic To hBMP
Graphic Get DC To hGraphicDC
Dialog Show Modal hDlg Call DlgProc
'shut downn GDI+
GdiplusShutdown token
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_ButtonSave : GDIPLus_SaveImageFromGraphicControlToGIFFile("image/gif", EXE.Path$ + "test.gif")
Case %IDC_ButtonLoad : GDIPlus_LoadImageFromFileToGraphicControl : Graphic ReDraw
End Select
End Select
End Function
Sub GDIPLus_SaveImageFromGraphicControlToGIFFile(sMimeType As String, fName As String)
Local s As String, sEncoderClsid As Guid, pImage, hBitmap As Dword
s = GDIPlusGetEncoderClsid(sMimeType)
sEncoderClsid = Guid$(s)
fName = UCode$(fName)
'from graphic target hDC
hBitmap = GetCurrentObject(hGraphicDC, %OBJ_Bitmap) 'from graphic target
'from clipboard
OpenClipboard %Null
hBitmap = GetClipboardData(%CF_Bitmap)
GDIpCreateBitmapFromHBITMAP( hBitmap, ByVal %Null, pImage) 'create GDI+ image (pImage)
GdipSaveImageToFile(pImage,StrPtr(fName),sEncoderClsid, ByVal %Null) 'save to GIF file
If pImage Then GdipDisposeImage(pImage) 'cleanup
End Sub
Sub GDIPlus_LoadImageFromFileToGraphicControl ' - load/display image onto Graphic control
Local pGraphics, pImage As Dword, strFileName As String, w,h As Long
GdipCreateFromHDC(hGraphicDC, pGraphics) 'get pGraphics - graphic object
'create image object, from file
strFileName = UCode$("garyface.gif") 'image source file
GdipLoadImageFromFile(StrPtr(strFileName), pImage) 'get pImage - image object
GdipDrawImage(pGraphics, pImage, 0, 0) 'draw image on graphic object
If pImage Then GdipDisposeImage(pImage) 'cleanup
If pGraphics Then GdipDeleteGraphics(pGraphics) 'cleanup
End Sub
'gbs_00963
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm