Page 1 of 2

Alpha-Blended-BMP => the easy way

Posted: Tue Mar 24, 2009 1:41 pm
by ukoenig
Hello,

after testing many graphic-applications :
Photoshop, Gimp, Icofx, xNview and more, I found a new two step-solution,
also to understand and useful for non experienced graphic-users.
The tool is designed, to make it easy, to convert to a Image with a Alpha-Blended background.

A situation could be :
Painting some transparent areas in a existing normal BMP and convert to Alpha-Blended.
How to do this, I will describe / add the solution in this toppic.

Download Pixelformer :
http://www.qualibyte.com/

The working-File : PNG-format with transparent-Background ( import )
Image

The Export Alpha-Blended-BMP-File
Image

After the given Export-BMP-Filename,
the Setting for Alpha-Blended-BMP ( automaticly detects the needed values for best results )
Image

The result : Alpha-Blended-BMP
Syntax for Alpha-Blended-BMP's to be used :
.....
.....
DEFINE BITMAP oBmp FILENAME "LOGO.bmp"

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT ( ABPaint( hDC, 20, 20, oBmp:hBitmap, 220 ) )
.....
.....


Image

Regards
Uwe :lol:

Re: Alpha-Blended-BMP => the easy way

Posted: Tue Mar 24, 2009 3:14 pm
by Silvio
Uwe, this is free ?

Re: Alpha-Blended-BMP => the easy way

Posted: Tue Mar 24, 2009 3:40 pm
by ukoenig
Hello Silvio,

This application is FREE of charge.
It works perfect and does exactly the things I need. All other applications are difficultly, to handle this.
The application is specially designed as solution for Alpha-Blending.
You can define transparentcy for BMP, JPG, PNG, TGA, ICO, CUR straight inside the loaded image.
I'm not sure, for how long it will be free of charge. It is the new Beta-release.

A sample from FWH\bitmaps\beach.bmp ( normal BMP ) converted to Alpha-Blended,
making a paper-effect. It is possible now, to make any normal BMP / JPG transparent.
Before, I converted to PNG at first, but now it works with a straight define of the Alpha-Channel
Select => Project => Image properties.
If You load a PNG-file, there is nothing to do, because the Alpha-Channel is defined already.

Download : Screenshot-selection < How to do it >
http://www.pflegeplus.com/fw_downloads/alpha.zip

1. Import the Image
2. Set Image properties
3. Select TRANSPARENT-color for the brush-tool from the color-picker.
4. Paint the borders / areas transparent with the brush-tool
or select the magic tool to choose a color to make transparent.
5. Save ( export ) as BMP like shown on top.

After loading the BMP-file, you have to change the format before painting, to get the Alpha-Channel
Project => Image properties

Image

The Result after export to BMP ( see : how to save on top )

Image

Saved as Alpha-Blended-BMP transparent

Some tools make it easy, to change a color to transparent
The magic-tool detects the area of a selected color

Image

Regards
Uwe :lol:

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 11:05 am
by ukoenig
Hello,

after creating some hight-quality Alpha-Blended-BMP's
with very good results :

DEFINE BITMAP oBmp FILENAME "LOGO.bmp"
...
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT ( ABPaint( hDC, 20, 20, oBmp:hBitmap, 220 ) )


I tested with :

@ 10, 10 BITMAP oBmp1 FILENAME "LOGO.bmp" NOBORDER
oBmp:lTransparent := .T.
oBmp:Refresh()


it doesn't display the BMP.
I changed the transparent area to black and there was no display.

Is there a difference of the used BMP-quality ( BMP 24 Bits for Alpha-Blending ) ?

Regards
Uwe :roll:

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 12:01 pm
by anserkk
Dear Mr.Uwe,

You need to modify the class TBitmap to call AbPaint in the Paint method. The same applies to TButtonBmp.
If you search for AlphaBmp you will find the details about the required modifications in those classes. A Data named lAlphaBmp is set to .T. to display AlphaBmp's. In the Method Paint based on the value of lAlphaBmp the required paint method is called ie either AbPaint or the default Paint

Regards

Anser

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 12:23 pm
by Silvio
do you try with

LOCAL oBrush := TBrush():New("NULL",,,)

@ 320, 15 BITMAP oApp:oLogoBmp FILENAME ".\bitmaps\LOGOSYST2.BMP" NOBORDER PIXEL OF oApp():oDlg
oApp:oLogoBmp:nClrPane := GetSysColor(3)
oApp:oLogoBmp:lTransparent := .t.
oApp:oLogoBmp:oBrush := oBrush
oApp:oLogoBmp:oCursor:= oCursor
oApp:oLogoBmp:bLClicked := {|| GoWeb("www.rivamania.it")}

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 1:31 pm
by James Bott
>A Data named lAlphaBmp is set to .T. to display AlphaBmp's.

It would nice if the program could automatically detect if the BMP was alpha and then use the correct paint method. Does anyone know how?

Regards,
James

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 1:39 pm
by Antonio Linares
James,

Lets check this thread in stackoverflow and lets see what is the final solution:

http://stackoverflow.com/questions/685684/how-to-programmatically-detect-if-a-bitmap-has-alpha-channel

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 9:42 pm
by James Bott
Antonio,

I don't understand it, but maybe this code will help:

http://stackoverflow.com/questions/3335 ... an-hbitmap

James

Re: Alpha-Blended-BMP => the easy way

Posted: Thu Mar 26, 2009 9:49 pm
by James Bott
Here is a C++ class (free) that does all kinds of bitmap manipulation. Maybe it is useful.

http://www.codeproject.com/KB/graphics/CBitmapEx.aspx

James

Re: Alpha-Blended-BMP => the easy way

Posted: Fri Mar 27, 2009 11:18 pm
by Antonio Linares
A first prototype, though still is not properly working. Feedback is welcome :-)

test.prg

Code: Select all | Expand


#include "FiveWin.ch"

function Main()

   local oBmp

   // DEFINE BITMAP oBmp FILENAME "c:\fwh\bitmaps\about.bmp" // No alpha

   DEFINE BITMAP oBmp FILENAME "c:\fwh\bitmaps\AlphaBmp\trash.bmp" // with alpha

   MsgInfo( HasAlpha( oBmp:hBitmap ) )
   
   oBmp:End()

return nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( HASALPHA )
{
   HBITMAP hBmp = ( HBITMAP ) hb_parnl( 1 );
   HDC hDC = GetDC( GetDesktopWindow() );
   BITMAPINFO bmi;
   void * bits;
   unsigned long ul;
   BOOL bAlpha = FALSE;

   memset( &bmi, 0, sizeof( BITMAPINFO ) );
   bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );  

   GetDIBits( hDC, hBmp, 0, 1, NULL, &bmi, DIB_RGB_COLORS );

   // hb_retnl( bmi.bmiHeader.biSize );

   bits = hb_xgrab( bmi.bmiHeader.biSize );

   GetDIBits( hDC, hBmp, 0, bmi.bmiHeader.biHeight, &bits, &bmi, DIB_RGB_COLORS );

   for( ul = 0; ul < bmi.bmiHeader.biSize; ul += 4 )
      if( ( ( char * ) bits )[ ul + 3 ] != 0 )
         bAlpha = TRUE;    

   hb_xfree( bits );

   ReleaseDC( GetDesktopWindow(), hDC );
   
   hb_retl( bAlpha );
}

#pragma ENDDUMP
 

Re: Alpha-Blended-BMP => the easy way

Posted: Fri Mar 27, 2009 11:26 pm
by Antonio Linares
There was a bug in the code. Still it is not working properly:

test.prg

Code: Select all | Expand


#include "FiveWin.ch"

function Main()

   local oBmp

   // DEFINE BITMAP oBmp FILENAME "c:\fwh\bitmaps\about.bmp" // No alpha

   DEFINE BITMAP oBmp FILENAME "c:\fwh\bitmaps\AlphaBmp\trash.bmp" // with alpha

   MsgInfo( HasAlpha( oBmp:hBitmap ) )
   
   oBmp:End()

return nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( HASALPHA )
{
   HBITMAP hBmp = ( HBITMAP ) hb_parnl( 1 );
   HDC hDC = GetDC( GetDesktopWindow() );
   BITMAPINFO bmi;
   void * bits;
   unsigned long ul;
   BOOL bAlpha = FALSE;

   memset( &bmi, 0, sizeof( BITMAPINFO ) );
   bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );  

   GetDIBits( hDC, hBmp, 0, 1, NULL, &bmi, DIB_RGB_COLORS );

   bits = hb_xgrab( bmi.bmiHeader.biSizeImage );

   GetDIBits( hDC, hBmp, 0, bmi.bmiHeader.biHeight, &bits, &bmi, DIB_RGB_COLORS );

   for( ul = 0; ul < bmi.bmiHeader.biSize; ul += 4 )
      if( ( ( char * ) bits )[ ul + 3 ] != 0 )
         bAlpha = TRUE;    

   hb_xfree( bits );

   ReleaseDC( GetDesktopWindow(), hDC );
   
   hb_retl( bAlpha );
}

#pragma ENDDUMP
 

Re: Alpha-Blended-BMP => the easy way

Posted: Fri Mar 27, 2009 11:34 pm
by Antonio Linares
Another bug fixed. Still no properly working:

test.prg

Code: Select all | Expand


#include "FiveWin.ch"

function Main()

   local oBmp

   // DEFINE BITMAP oBmp FILENAME "c:\fwh\bitmaps\about.bmp" // No alpha

   DEFINE BITMAP oBmp FILENAME "c:\fwh\bitmaps\AlphaBmp\explorer.bmp" // with alpha

   MsgInfo( HasAlpha( oBmp:hBitmap ) )
   
   oBmp:End()

return nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( HASALPHA )
{
   HBITMAP hBmp = ( HBITMAP ) hb_parnl( 1 );
   HDC hDC = GetDC( GetDesktopWindow() );
   BITMAPINFO bmi;
   void * bits;
   unsigned long ul;
   BOOL bAlpha = FALSE;

   memset( &bmi, 0, sizeof( BITMAPINFO ) );
   bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );  

   GetDIBits( hDC, hBmp, 0, 1, NULL, &bmi, DIB_RGB_COLORS );

   bits = hb_xgrab( bmi.bmiHeader.biSizeImage );

   GetDIBits( hDC, hBmp, 0, bmi.bmiHeader.biHeight, &bits, &bmi, DIB_RGB_COLORS );

   for( ul = 0; ul < bmi.bmiHeader.biSizeImage; ul += 4 )
      if( ( ( char * ) bits )[ ul + 3 ] != 0 )
         bAlpha = TRUE;    

   hb_xfree( bits );

   ReleaseDC( GetDesktopWindow(), hDC );
   
   hb_retl( bAlpha );
}

#pragma ENDDUMP
 

Re: Alpha-Blended-BMP => the easy way

Posted: Sat Mar 28, 2009 4:19 am
by anserkk
Dear Mr.Antonio,

Really appreciate your effort. :D

HasAlpha( oBmp:hBitmap ) is returning .F. eventhough the Bitmap c:\fwh\bitmaps\AlphaBmp\explorer.bmp contains AlphaChannel. Hope that we will be able to solve this bug very soon.

Regards

Anser

Re: Alpha-Blended-BMP => the easy way

Posted: Sat Mar 28, 2009 9:29 pm
by Antonio Linares
Lets see if we get an answer from the Microsoft GDI group:

http://groups.google.es/group/microsoft ... 930?hl=es#

Also in the FreeImage forum:

https://sourceforge.net/forum/forum.php ... m_id=36111