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_Graphic = 500
%IDC_Button = 501
Global hDlg,hBMP() As Dword
Global pImage, pGraphics, token As Dword, StartupInput As GdiplusStartupInput
Global qFreq, qStart, qStop As Quad
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",,,450,440, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button, "Load Images", 10,10,150,25
Control Add Graphic, hDlg, %IDC_Graphic,"", 0,40,450,400
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i As Long
Select Case Cb.Msg
Case %WM_InitDialog
QueryPerformanceFrequency qFreq
'initialize GDI
StartupInput.GdiplusVersion = 1 'initialize GDIPlus
GdiplusStartup(token, StartupInput, ByVal %NULL) 'initialize GDIPlus
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
LoadImages
End Select
Case %WM_Destroy
If pImage Then GdipDisposeImage(pImage) 'cleanup
If pGraphics Then GdipDeleteGraphics(pGraphics) 'cleanup
GdiplusShutdown token 'shutdown GDI+
End Select
End Function
Sub LoadImages
Local i, iCount As Long
QueryPerformanceCounter qStart
'load the same image many times
iCount = 1000
ReDim hBMP(iCount)
For i = 1 To UBound(hBMP) : LoadImageToMemoryBitmap "baby.jpg", hBMP(i) : Next i
'just for reference, show the image
Graphic Attach hDlg, %IDC_Graphic
Graphic Copy hBMP(1), 0
QueryPerformanceCounter qStop
Dialog Set Text hDlg, Format$((qStop-qStart)/qFreq,"###.000") & " seconds"
End Sub
Sub LoadImageToMemoryBitmap (ImgName As String, hBMP As Dword)
Local hDC As Dword, w,h As Long
GdipLoadImageFromFile((ImgName), pImage) 'load image
GdipGetImageWidth(pImage,w) 'get width
GdipGetImageHeight(pImage, h) 'get height
Graphic Bitmap New w,h To hBMP
Graphic Attach hBMP, 0
Graphic Get DC To hDC
GdipCreateFromHDC(hDC, pGraphics) ' Create the Graphic object
GdipDrawImage(pGraphics, pImage, 0, 0) ' Draw the image
End Sub
http://www.garybeene.com/sw/gbsnippets.htm