Painting alpha blended bmp on windows

Painting alpha blended bmp on windows

Postby hua » Fri Jan 15, 2021 6:54 am

Hi guys,
When I use the code below, my alpha blended bmp is painted with black background instead of being transparent.
Which part I went wrong?

Code: Select all  Expand view  RUN

     hBmp2 := ReadBitMap(0, ud_bmpDir()+"\2021.bmp")
     DrawBitmap( hDC, hBmp2, nTop, nLeft)
 


TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Painting alpha blended bmp on windows

Postby ukoenig » Fri Jan 15, 2021 2:46 pm

There is a function

ABPaint( hDC := GetWindowDC( hWnd ), nLeft, nTop, oBmp:hBitmap )

sample testab.prg

DEFINE BITMAP oBmp FILENAME "..\bitmaps\AlphaBmp\Trash.bmp"
...
...
ACTIVATE WINDOW oWnd ;
ON PAINT ABPaint( hDC, 10, 10, oBmp:hBitmap, 220 ) // 0-255 transparency level

or You can use a GDIPLUS-solution
sample :

Code: Select all  Expand view  RUN

// image location
c_Path := cFilePath(GetModuleFileName( GetInstance() ) )
c_Path1 :=  c_Path + "BITMAPS\"
...
...
// inside window define
oWnd:bPainted := < |hDC|
    DRAWIMAGE( oWnd )
RETURN NIL
>
...
...

/ -----------------

FUNCTION DRAWIMAGE( oWnd )
LOCAL oGraphics := Graphics():New( oWnd:hDC )
LOCAL oImage    := GDIBmp():new( c_path1 + "
FWH.bmp" ) // Image

// position top, left
oGraphics:DrawImage( oImage, 493, 15, oImage:GetWidth(), oImage:GetHeight() )

oGraphics:Destroy()
oImage:End()

RETURN NIL


regards
Uwe :D
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: Painting alpha blended bmp on windows

Postby hua » Fri Jan 15, 2021 6:18 pm

Uwe,
Thank you!
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 66 guests