Page 1 of 4

Display Alpha channel 32 bit BMP on ButtonBMP (Solved)

PostPosted: Tue Dec 30, 2008 12:17 pm
by anserkk
Hi,

I understand that Borland Resource Compiler does not support Alpha channel BMP's, I have used "Pelles C" resource compiler to compile the .RC file without any error's.

Unfortunately the ButtonBMP is not displaying the image. (No errors).

I hope ButtonBMP support's 32bit Alpha BMP's.

Any hint?

Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Tue Dec 30, 2008 12:49 pm
by Antonio Linares
Anser,

CLASS TButtonBmp METHOD Paint() calls DrawMasked() to paint the bitmap.

If you change that call into ABPaint(), as used in FWH\samples\TestAB.prg then you may be able to use the Alpha channel :-)

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Tue Dec 30, 2008 1:14 pm
by anserkk
Dear Mr.Antonio,

Anser,

CLASS TButtonBmp METHOD Paint() calls DrawMasked() to paint the bitmap.

If you change that call into ABPaint(), as used un FWH\samples\TestAB.prg then you may be able to use the Alpha channel


Does it mean that I have to change the code in ButtonB.prg ?

Or is there a way to do it without changing the source code of the Class TButtonBmp ?

TestAb.Prg
Code: Select all  Expand view
ACTIVATE WINDOW oWnd ;
      ON PAINT ABPaint( hDC, 10, 10, oBmp:hBitmap, 220 ) // 0-255 transparency level


Like we call ON PAINT while ACTIVATE WINDOW is there a way to call the ButtonBMP's paint method ?


Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Tue Dec 30, 2008 1:53 pm
by Antonio Linares
Anser,

> Does it mean that I have to change the code in ButtonB.prg ?

yes, thats what I meant

> Or is there a way to do it without changing the source code of the Class TButtonBmp ?

xharbour allows to replace a Class Method without modifying the class original source code.

Please make a search for OVERRIDE METHOD in these forums :-)

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Fri Jan 02, 2009 7:56 am
by anserkk
I am little bit confused regarding the display of Alpha Channel BMP on a BUTTONBMP control

The following code is dispalying Alpha Channel BMP (I have used the FileName)

Code: Select all  Expand view
@14.3,05 BUTTONBMP oBtnCancel PROMPT "Close" OF oDlg TEXTRIGHT BITMAP "Images/AnsTest.Bmp" ;
   SIZE 50,15 ACTION oDlg:End()


But if I use ResourceName instead of the file name then it will not display the AlphaChannel BMP

Code: Select all  Expand view
@14.3,05 BUTTONBMP oBtnCancel PROMPT "Close" OF oDlg TEXTRIGHT BITMAP "AnsTest" ;
   SIZE 50,15 ACTION oDlg:End()


I have not used ABPaint(). (I have not modified the original class) Any hint why filename is working and resource name is not working ?

My .RC
Code: Select all  Expand view
AnsTest              BITMAP  Images\AnsTest.Bmp
#ifdef __FLAT__
  1 24 "Images/WindowsXP.Manifest"
#endif


Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Fri Jan 02, 2009 9:12 am
by Antonio Linares
Anser,

Try to export the bitmap from the resource file to an external file and check if the alpha channel remains active.

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Fri Jan 02, 2009 9:56 am
by anserkk
Dear Mr.Antonio,

I exported the BMP from my .RES file using the Resource Editor ResEdit.

When I checked the exported BMP file using Adobe PhotoShop CS3, I found that Alpha Channel exists in this BMP.

As I am not an expert in Graphic formats, I compared the properties of this particular BMP with some of the files contained in the folder \FWH\Bitmaps\AlphaBmp. It appears to be the same.

Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Fri Jan 02, 2009 10:10 am
by Antonio Linares
Anser,

Then you may need to use ABPaint() as we have commented you.

When a bitmap is loaded from disk, we manage it with our own code. But when it is loaded from resources, we use Windows APIs own code. Thats where the difference may come from.

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Fri Jan 02, 2009 10:12 am
by anserkk
Thankyou Mr.Antonio,

I shall try as you suggested and shall let you know the result.

Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Fri Jan 02, 2009 10:29 am
by anserkk
Dear Mr.Antonio,

I tried replacing DrawMasked() with ABPaint() in the METHOD Paint() of TButtonBMP (ButtonB.Prg), unfortunately the picture is not getting displayed on ButtonBMP


Code: Select all  Expand view
      if ::lActive
       /*  DrawMasked( ::hDC, ::hBitmap, nTop + If( lPressed, 1, 0 ),;
                     nLeft + If( lPressed, 1, 0 ) )   */
         ABPaint( ::hDC,  nTop + If( lPressed, 1, 0 ), nLeft + If( lPressed, 1, 0 ) , ::hBitmap, 220 )
      else
         DrawGray( ::hDC, ::hBitmap, nTop + If( lPressed, 1, 0 ),;
                     nLeft + If( lPressed, 1, 0 ) )
      endif                     


This is the download link of the BMP file. I tried ImageShack but after uploading BMP will get converted to PNG
http://rapidshare.com/files/178967440/AnsTest.bmp.html

Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Sat Jan 03, 2009 8:14 am
by Antonio Linares
Anser,

It seems as we are facing the same problem again. Your bitmap is loaded from resources, isn't it ?

Windows API seems not to be respecting the alpha channel when loading it from resources.

But our function DibRead() does respect it.

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Sat Jan 03, 2009 8:23 am
by anserkk
Your bitmap is loaded from resources, isn't it ?


Yes, Mr.Antonio

Windows API seems not to be respecting the alpha channel when loading it from resources.


So sad

Regards

Anser

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Sat Jan 03, 2009 8:29 am
by Antonio Linares

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Sat Jan 03, 2009 8:35 am
by Antonio Linares

Re: Display Alpha channel 32 bit BMP on ButtonBMP

PostPosted: Sat Jan 03, 2009 9:21 am
by anserkk
Thankyou Mr.Antonio,

Regards

Anser