Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
#Include "CGDIPLUS.inc"
%IDC_GraphicA = 500
Global hDlg,hWinA,hGraphic As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,320,320, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_GraphicA,"", 0,0,320,320
Control Handle hDlg, %IDC_GraphicA To hGraphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
LoadImageToClipboard "girl.jpg"
End Select
End Function
Sub LoadImageToClipboard (ImgName As String)
Local pGraphics,pImage,hDC,token,hWin As Dword
Local w,h As Long, StartupInput As GdiplusStartupInput
'initialize GDI
StartupInput.GdiplusVersion = 1 'initialize GDIPlus
GdiplusStartup(token, StartupInput, ByVal %NULL) 'initialize GDIPlus
GdipLoadImageFromFile((ImgName), pImage) 'load image
GdipGetImageWidth(pImage,w) 'get width
GdipGetImageHeight(pImage, h) 'get height
Graphic Bitmap New w,h To hWin
Graphic Attach hWin, 0
Graphic Get DC To hDC
GdipCreateFromHDC(hDC, pGraphics) ' Create the Graphic object
GdipDrawImage(pGraphics, pImage, 0, 0) ' Draw the image
Clipboard Reset
Clipboard Set Bitmap hWin
If pImage Then GdipDisposeImage(pImage) 'cleanup
If pGraphics Then GdipDeleteGraphics(pGraphics) 'cleanup
GdiplusShutdown token 'shutdown GDI+
End Sub
'gbs_01317
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm