Hi,
How I do to detect a bitmap format (16bpp/32bpp) *after* I'd loaded it please?
Thanks and regards,
Toninho.
#define TAB Chr(9)
...
nH := FOpen (cBmp)
MsgInfo (BmpInfo (nH)
FClose (nH)
...
//-------------------------------------------------------------------//
FUNCTION BmpInfo (nH, cBmp)
LOCAL i, cInfo := ""
LOCAL aInfoText := {"Bitmaptype"+TAB+": ",;// : ",;
"Size"+TAB+TAB+": ",;// : ",;
"reserved"+TAB+TAB+": ",;// :",;
"reserved"+TAB+TAB+": ",;// :",;
"Data offset"+TAB+": ",;// : ",;
"Header Size"+TAB+": ",;// : ",;
"Width"+TAB+TAB+": ",;// : ",;
"Height"+TAB+TAB+": ",;// : ",;
"No planes"+TAB+": ",;// : ",;
"Bits/pixel"+TAB+TAB+": ",;// : ",;
"Compression"+TAB+": ",;// : ",;
"Image Data size"+TAB+": ",;// : ",;
"horz. pixel/meter"+TAB+": ",;//: ",;
"Vert. pixel/meter"+TAB+": ",;//: ",;
"No of colors"+TAB+": ",;// : ",;
"Important colors"+TAB+": " }
aInfo := Array (20)
IF nH > 0
aInfo[1] := Chr (FReadByte (nH, 0, 1)) +; // Typ
Chr (FReadByte (nH, 1, 1))
aInfo[2] := FReadByte (nH, 2,4) // Filesize
aInfo[3] := FReadByte (nH, 6,2) // reserved, 0
aInfo[4] := FReadByte (nH, 8,2)
aInfo[5] := FReadByte (nH, 10,4) // Data offset
aInfo[6] := FReadByte (nH, 14,4) // size of BitmapInfoHeader
aInfo[7] := FReadByte (nH, 18,4) // width
aInfo[8] := FReadByte (nH, 22,4) // height
aInfo[9] := FReadByte (nH, 26,2) // no of planes, must be 0
aInfo[10] := FReadByte (nH, 28,2) // no of bits / pixel
aInfo[11] := FReadByte (nH, 30,4) // compression type
aInfo[12] := FReadByte (nH, 34,4) // size of image dat in bytes, 0 when no compression
aInfo[13] := FReadByte (nH, 38,4) // horz. pixel / meter
aInfo[14] := FReadByte (nH, 44,4) // vert. pixerl / meter
aInfo[15] := FReadByte (nH, 46,4) // no of colors
aInfo[16] := FReadByte (nH, 50,4) // no of important colors
//aInfo{17] := FReadByte (nH, 54,4) //
cInfo := cBmp+CRLF
FOR i := 1 TO 16
cInfo += aInfoText[i]+cValToChar (aInfo[i])+CRLF
NEXT
ENDIF
RETURN (cInfo)
//-------------------------------------------------------------------//
FUNCTION FReadByte (nH, nOffset, nLen, lHex)
LOCAL i, cBuffer, xByte, nByte
DEFAULT lHex := .f. // return hex numbers
FSeek (nH, nOffset, 0)
cBuffer := Space (nLen)
FRead (nH, @cBuffer, nLen)
IF nLen = 4 // 32 bit
nByte := Bin2L (cBuffer)
ELSE
nByte := Bin2I (cBuffer)
ENDIF
xByte := IIF (!lHex, nByte, Lower (DecToHex (nByte)) )
IF lHex
IF Len(xByte)<2
xByte := "0"+xByte
ENDIF
ENDIF
//? cByte, DecToHex (nByte), Len(cByte), Empty(cByte)
RETURN (xByte)
HB_FUNC( BMPFORMAT ) // hBitmap --> nBitsPixel
{
BITMAP bm;
GetObject( ( HBITMAP ) hb_parnl( 1 ), sizeof( BITMAP ), ( LPSTR ) &bm );
hb_retnl( bm.bmBitsPixel );
}
Antonio Linares wrote:Toninho,
Try this:
- Code: Select all Expand view
HB_FUNC( BMPFORMAT ) // hBitmap --> nBitsPixel
{
BITMAP bm;
GetObject( ( HBITMAP ) hb_parnl( 1 ), sizeof( BITMAP ), ( LPSTR ) &bm );
hb_retnl( bm.bmBitsPixel );
}
toninhofwi wrote:Stefan, thanks for your help. Do you know if there are any way to use bitmap handle? Something like: GetBitmapFormat( oBmp:hBitmap ) ?
Antonio Linares wrote:Toninho,
Maybe we could try to check these struct members:
HB_FUNC( BMPALPHA ) // hBitmap --> lYesNo
{
BITMAP bm;
GetObject( ( HBITMAP ) hb_parnl( 1 ), sizeof( BITMAP ), ( LPSTR ) &bm );
hb_retl( bm.bmBitsPixel == 32 );
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: nageswaragunupudi and 95 guests