Alpha-Blended-BMP => the easy way

Alpha-Blended-BMP => the easy way

Postby ukoenig » Tue Mar 24, 2009 1: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 )
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:
Last edited by ukoenig on Wed Jul 15, 2009 12:12 am, edited 6 times in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

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

Postby Silvio » Tue Mar 24, 2009 3:14 pm

Uwe, this is free ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

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

Postby ukoenig » Tue Mar 24, 2009 3: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

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:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

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

Postby ukoenig » 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 :roll:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

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

Postby anserkk » 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
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

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

Postby Silvio » 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:oLogoBmp:nClrPane := GetSysColor(3)
oApp:oLogoBmp:lTransparent := .t.
oApp:oLogoBmp:oBrush := oBrush
oApp:oLogoBmp:oCursor:= oCursor
oApp:oLogoBmp:bLClicked := {|| GoWeb("www.rivamania.it")}
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

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

Postby James Bott » Thu Mar 26, 2009 1: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

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

Postby Antonio Linares » Thu Mar 26, 2009 1: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41344
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby James Bott » Thu Mar 26, 2009 9:42 pm

Antonio,

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

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

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

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

Postby James Bott » Thu Mar 26, 2009 9: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

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

Postby Antonio Linares » Fri Mar 27, 2009 11:18 pm

A first prototype, though still is not properly working. Feedback is welcome :-)

test.prg
Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41344
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Fri Mar 27, 2009 11:26 pm

There was a bug in the code. Still it is not working properly:

test.prg
Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41344
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Fri Mar 27, 2009 11:34 pm

Another bug fixed. Still no properly working:

test.prg
Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41344
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby anserkk » Sat Mar 28, 2009 4: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
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

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

Postby Antonio Linares » Sat Mar 28, 2009 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41344
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 15 guests

cron