How to paint a transparent bitmap on a bitmap ?

Post Reply
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

How to paint a transparent bitmap on a bitmap ?

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post by RAMESHBABU »

Hello Mr.Antonio

Thank you very much.

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

Regards

- Ramesh Babu P
Post Reply