Date: 02-16-2022
Return to Index
created by gbSnippets
Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As Long array of RGBQuad
End Type
Type BITMAPINFOHEADER
biSize As Dword number of bytes required by the structure
biWidth As Long width of bitmap
biHeight As Long height of bitmap
biPlanes As Word number of planes (1)
biBitCount As Word bits-per-pixel
biCompression As Dword %BI_RGB (uncompressed)
biSizeImage As Dword 0 'size (bytes) of image
biXPelsPerMeter As Long 0
biYPelsPerMeter As Long 0
biClrUsed As Dword 0 '# color indexes in table that are used
biClrImportant As Dword 0 '# color indexes required to display bitmap
End Type
But that would be even faster without using the DDT (Graphic Get Bits To bmp$)
and reading directly using the core API GetObject/GetDIBits
Code:
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
GetDIBits(hdc, hbmp, uStartScan, cScanLines, lpvBits, lpbi, uUsage)
hdc Handle to the device context.
hbmp Handle to bitmap. Must be a compatible bitmap (DDB)
uStartScan The first scan line to retrieve.
cScanLines The number of scan lines to retrieve.
lpvBits [out] Pointer to buffer to receive bitmap data.
If NULL, the function passes the dimensions and format
of the bitmap to the BITMAPINFO structure (lpbi)
lpbi Pointer to BITMAPINFO structure that specifies
desired format for the DIB data.
uUsage %DIB_RGB_COLORS
DC handle 1st #lines ptr to buffer ptr to BM
GetDIBits(hMemoryDC,hBitMap, 0, 0, ByVal %Null, ByVal VarPtr(bm), %DIB_RGB_Colors
GetDIBits(hTmpDC, hBitmap, 0, ySize, PixelArray(0), ByVal VarPtr(bi), %DIB_RGB_Colors
GetDIBits(memDC, hBmp, 0, yp, ByVal bitsPtr, ByVal VarPtr(bmInfo), %DIB_RGB_Colors
GetDIBits(hDC, hbm, 0, bm.bmheight, ByVal mem&, bi, %DIB_RGB_Colors
GetDIBits(hDC, hBMP, 0, pbih.biHeight, ByVal StrPtr(lpBits), ByVal VarPtr(pbi), %DIB_RGB_Colors
GetDIBits(lngDC, hBmSrc, 0, bmiHeader.biHeight, bImgData(1), bmpInfo, %DIB_RGB_Colors
GetDIBits(memDC, hBmp, 0, yp, ByVal bitsPtr, ByVal VARPTR(bmInfo), %DIB_RGB_COLORS)
SetDIBits hDC, hBitmap, uStartScan, cScanLines, lpvBits, lpbmi, fuColorUse
hdc [in] A handle to a device context.
hbmp [in] A handle to the compatible bitmap (DDB)
uStartScan [in] The starting scan line
cScanLines [in] The number of scan lines
lpvBits [in] A pointer to the DIB color data, stored as an array of bytes.
The format of the bitmap values depends on the biBitCount
member of the BITMAPINFO structure pointed to by the lpbmi parameter.
lpbmi [in] A pointer to a BITMAPINFO structure that contains
information about the DIB.
fuColorUse [in] %DIB_RGB_COLORS
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg, hBMP, hDC, hDCB, hMemDC As Dword
Global B() As Long
%IDC_Button = 500
%IDC_Graphic = 600
%IDC_GraphicB = 700
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,120,160, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 10,10,100,20
Control Add Graphic, hDlg, %IDC_Graphic,"Push", 10,40,100,100, %WS_Border
Graphic Attach hDlg, %IDC_Graphic, Redraw
Graphic Render "cowgirl.bmp", (0,0)-(99,99)
Graphic Get DC To hDC
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x,y,iResult As Long, bm As Bitmap, bmi As BitmapInfo
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_Button And Cb.CtlMsg = %BN_Clicked Then
hBMP = GetCurrentObject(hDC,%OBJ_Bitmap)
GetObject(hBMP,SizeOf(bm),bm)
ReDim B(1 To bm.bmwidth,1 To bm.bmheight) 'color array
bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader)
bmi.bmiHeader.biWidth = bm.bmWidth
bmi.bmiHeader.biHeight = -bm.bmHeight ' Put top in TOP instead on bottom!
bmi.bmiHeader.biPlanes = 1
bmi.bmiHeader.biBitCount = 32
bmi.bmiHeader.biCompression = %BI_RGB
GetDIBits hDC, hBMP, 0, bm.bmHeight, B(1,1), bmi, %DIB_RGB_COLORS
For y = 1 To bm.bmheight
For x = 1 To bm.bmwidth
B(x,y) = 64
Next x
Next y
SetDIBits hDC, hBMP, 0, bm.bmHeight, B(1,1), bmi, %DIB_RGB_COLORS
Graphic ReDraw
End If
End Function
'gbs_00955
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm