FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Alpha-Blended-BMP => the easy way
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Alpha-Blended-BMP => the easy way
Posted: Tue Mar 24, 2009 01:41 PM
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 )


The Export Alpha-Blended-BMP-File


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


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 ) )
.....
.....




Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: Alpha-Blended-BMP => the easy way
Posted: Tue Mar 24, 2009 03:14 PM

Uwe, this is free ?

Best Regards, Saludos



Falconi Silvio
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Alpha-Blended-BMP => the easy way
Posted: Tue Mar 24, 2009 03:40 PM
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



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



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



Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 11:05 AM
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 :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 12:01 PM

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

Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 12:23 PM
do you try with

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

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



Falconi Silvio
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 01:31 PM

>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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 01:39 PM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 09:42 PM

Antonio,

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

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

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Thu Mar 26, 2009 09:49 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Fri Mar 27, 2009 11:18 PM
A first prototype, though still is not properly working. Feedback is welcome :-)

test.prg
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Fri Mar 27, 2009 11:26 PM
There was a bug in the code. Still it is not working properly:

test.prg
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Fri Mar 27, 2009 11:34 PM
Another bug fixed. Still no properly working:

test.prg
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Sat Mar 28, 2009 04:19 AM

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

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Alpha-Blended-BMP =&gt; the easy way
Posted: Sat Mar 28, 2009 09:29 PM

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

regards, saludos

Antonio Linares
www.fivetechsoft.com