Page 1 of 1

How to paint a transparent bitmap on a bitmap ?

Posted: Sat Nov 25, 2006 5:04 pm
by RAMESHBABU
Hi

Can anybody suggest me how to paint a transparent bitmap on a bitmap
painted at a particular location of a non-brushed dialog ?

Code: Select all

// Text on a bitmap

#include "FiveWin.ch"

FUNC main() 

   local oWnd, oBmp, oBmp1

   DEFINE WINDOW oWnd TITLE "Text on a bitmap" 

   @ 1, 1 BITMAP oBmp FILENAME "..\bitmaps\magic.bmp" OF oWnd 

   oBmp:bPainted = { || SetBkMode( oBmp:hDC, 1 ),; 
                        SetTextColor( oBmp:hDC, CLR_YELLOW ),;
                        TextOut( oBmp:hDC, 5, 5, "Hello" ) } 

   @ 2, 1 BITMAP oBmp1 FILENAME "..\bitmaps\book.bmp" OF oBmp NO BORDER

   ACTIVATE WINDOW oWnd 

RETURN NIL 

The Result is :

Image

But I want the book's background should get merged with the image in the background of the lady in the picture.


Thanks

- Ramesh Babu P

Posted: Sat Nov 25, 2006 6:06 pm
by Antonio Linares
Ramesh,

Code: Select all

#include "FiveWin.ch" 

FUNC main() 

   local oWnd, oBmp, oBmp1, hBitmap

   DEFINE WINDOW oWnd TITLE "Text on a bitmap" 

   hBitmap := ReadBitmap( 0, "..\bitmaps\book.bmp" )

   @ 1, 1 BITMAP oBmp FILENAME "..\bitmaps\magic.bmp" OF oWnd 

   oBmp:bPainted = { || PaintTransparent( oBmp:hDC, hBitmap ),;
                        SetBkMode( oBmp:hDC, 1 ),; 
                        SetTextColor( oBmp:hDC, CLR_YELLOW ),; 
                        TextOut( oBmp:hDC, 5, 5, "Hello" ) }

   ACTIVATE WINDOW oWnd 

   DeleteObject( hBitmap )

RETURN NIL

function PaintTransparent( hDC, hBitmap )

   local hBmpOld := SelectObject( hDC, hBitmap )
   local nZeroZeroClr := GetPixel( hDC, 0, 0 )
   local nOldClr 

   SelectObject( hDC, hBmpOld )
   nOldClr = SetBkColor( hDC, nRGB( 255, 255, 255 ) )
   TransBmp( hBitmap, nBmpWidth( hBitmap ), nBmpHeight( hBitmap ),;
             nZeroZeroClr, hDC, 10, 20, nBmpWidth( hBitmap ), nBmpHeight( hBitmap ) )
   SetBkColor( hDC, nOldClr )          

return nil
Image
And change book.bmp this way:
Image

Posted: Sun Nov 26, 2006 10:39 am
by RAMESHBABU
Hello Mr.Antonio

Thank you very much.

Your function "PaintTransparent( hDC, hBitmap )" has done the job.

Regards

- Ramesh Babu P