by nageswaragunupudi » Sun Mar 29, 2009 1:40 pm
Congratulations that you finally got it.
Here is a small program using the above code to check all bitmap files in any selected folder and show which bitmaps have alpha channel and which do not.
- Code: Select all Expand view
#include "FiveWin.ch"
function Main()
local cDir := cGetDir( "Bitmap Directory", "c:\fwh\bitmaps" )
local aDir, aAlpha := {}
local n, oBmp
aDir := Directory( cDir + "\*.bmp" )
aEval( aDir, { |a| AAdd( aAlpha, { cDir + "\" + a[ 1 ], "no alpha" } ) } )
for n := 1 to Len( aAlpha )
DEFINE BITMAP oBmp FILENAME aAlpha[ n ][ 1 ]
if HasAlpha( oBmp:hBitmap )
aAlpha[ n ][ 2 ] := "HAS ALPHA"
endif
oBmp:End()
next n
xbrowse( aAlpha, cDir )
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
WORD DibNumColors( void * pv );
HANDLE DibFromBitmap( HBITMAP, DWORD, WORD, HPALETTE );
static WORD PaletteSize( void * pv )
{
LPBITMAPINFOHEADER lpbi = ( LPBITMAPINFOHEADER ) pv;
WORD NumColors = DibNumColors( lpbi );
if( lpbi->biSize == sizeof( BITMAPCOREHEADER ) )
return ( WORD )( NumColors * sizeof( RGBTRIPLE ) );
else
return ( WORD )( NumColors * sizeof( RGBQUAD ) );
}
HB_FUNC( HASALPHA ) // hBitmap --> lYesNo
{
HANDLE hDib = DibFromBitmap( ( HBITMAP ) hb_parnl( 1 ), 0, 0,
( HPALETTE ) hb_parnl( 2 ) );
BOOL bAlphaChannel = FALSE;
if( hDib )
{
LPBITMAPINFO lpbmi = ( LPBITMAPINFO ) GlobalLock( hDib );
unsigned char * uc = ( LPBYTE ) lpbmi + ( WORD ) lpbmi->bmiHeader.biSize + PaletteSize( lpbmi );
unsigned long ul;
for( ul = 0; ul < lpbmi->bmiHeader.biSizeImage; ul += 4 )
if( uc[ ul + 3 ] != 0 )
bAlphaChannel = TRUE;
GlobalUnlock( hDib );
}
hb_retl( bAlphaChannel );
}
#pragma ENDDUMP
Compile run and see the results in xbrowse for all bitmaps
Regards
G. N. Rao.
Hyderabad, India