Date: 02-16-2022
Return to Index
created by gbSnippets
'per Patrice Terrier
But that would be even faster without using the DDT
(Graphic Get Bits To bmp$) and reading directly using
the core API GetObject/GetDIBits
Local bm AS BITMAP
Local pBits AS BYTE PTR, P As Long
CALL GetObject(hDIB, SIZEOF(bm), bm)
pBits = bm.bmBits
FOR P = (bm.bmWidth * bm.bmHeight) TO 1 STEP - 1
A? = @pBits[3]
R? = @pBits[2]
G? = @pBits[1]
B? = @pBits[0]
pBits = pBits + 4
NEXT
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,220,250, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 200, "Push", 10,10,100,20
Control Add Graphic, hDlg, 100,"", 10,40,200,200, %WS_Border
Graphic Attach hDlg, 100
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 200 Then GetPixels
End Function
Sub GetPixels
Local bm As Bitmap, x,y,iColor As Long, pStart, pBits As Long Ptr
Local hDeskTopDC, hBMP As Dword
hDesktopDC = GetDC(%Null) 'DC to desktop
hBMP = GetCurrentObject(hDeskTopDC, %Obj_Bitmap) 'handle to bitmap in the Window
GetObject(hBMP, SizeOf(bm), bm)
pStart = bm.bmBits
iColor = @pBits
For x = 0 To 199
For y = 0 To 199
pBits = pStart + (y*bm.bmWidth+x)*4
iColor = @pBits
Graphic Set Pixel (x,y), iColor
Next Y
Next x
End Sub
'gbs_00865
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm