Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes you may want an application to work with only bitmaps
'of a certain bits per pixel resolution - such as 24bit or 32bit
'only bitmaps.
'This snippets shows how to get the bits-per-pixel value without
'loading the bitmap and without the use of API.
'Primary Code:
'Note: This works for a BMP image file only
Local bpp as Long
Open "cowgirl.bmp" For BINARY AS #1
Get #1, 19, bpp
Close #1
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Include "Win32API.inc"
Global hDlg as DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Method 1", 50,10,100,20
Control Add Button, hDlg, 200,"Method 2", 50,40,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local bpp As Long
Open "cowgirl.bmp" For BINARY AS #1
Get #1, 29, bpp
Close #1
MsgBox "Bits-per-pixel: " + Str$(bpp)
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
Local fh as Bitmapfileheader, ih as BitmapInfoHeader
Open "cowgirl.bmp" For BINARY AS #1
Get #1, , fh
Get #1, , ih
Close #1
MsgBox "Bits-per-pixel: " + Str$(ih.biBitCount)
End If
End Function
'gbs_00534
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm