Below is a sample code. The code read a 24-bit BMP file, store the raw data into a memory block "bp" and display onto the PictureBox. For your case instead of 24-bit pixel data, change the code to 8-bit data per pixel.
Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
Private Type RGBQUAD '4 bytes
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
Private Type BITMAPINFO '44 bytes
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
Private Const DIB_RGB_COLORS = 0&
Private Const BI_RGB = 0&
Private Sub Command1_Click()
Dim i As Long
Dim bp() As Byte
Dim bmppath As String
Dim bm As BITMAPINFO
bm.bmiHeader.biSize = Len(bm.bmiHeader)
bmppath = App.Path & "\test.bmp"
Open bmppath For Binary As #1
Get #1, 3, bm.bmiHeader.biSizeImage 'Not a reliable data
Get #1, 19, bm.bmiHeader.biWidth 'Use negative height to scan top-down.
Get #1, 23, bm.bmiHeader.biHeight
Get #1, 27, bm.bmiHeader.biPlanes
Get #1, 29, bm.bmiHeader.biBitCount 'Bits per pixel
Get #1, 31, bm.bmiHeader.biCompression 'BI_RGB
ReDim bp(bm.bmiHeader.biSizeImage - 1) As Byte
Get #1, 55, bp
Picture1.Width = bm.bmiHeader.biWidth
Picture1.Height = bm.bmiHeader.biHeight
i = SetDIBits(Picture1.hdc, _
Picture1.Visible = True
I'm trying to understand this all, I'm new to this area of programming. The program I'm building, I am opening a bitmap and setting it as the background of a "transparent" animated gif. I can set a background I import into my program as a bitmap. But, because the screen changes, and what's on the screen is what I need as the background, I'm having to do a screen capture to a file, which is successful. Now, unless there's a better way to do this and someone could help me, I need to open this bitmap file and set it to the background.
The function allows for either one of these two...
I'm not sure what exactly it's asking for. How can I incorporate your code, opening the bitmap, and then putting it to one of these?