FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour gdi transparent question
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
gdi transparent question
Posted: Sat Nov 08, 2025 04:59 PM

I load a png image with

oGraphics := Graphics():New( hDC )

oImage1:= GDIBmp():new(,::aNameImages[1] )
....
oGraphics:DrawImage( ::aImages , 1, aPos )

but gdiBmp then is not transparent

is there a command I not Know ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: gdi transparent question
Posted: Sun Nov 09, 2025 09:34 AM

PNG images loaded with GDIBmp should display transparently by default when using Graphics:DrawImage(). Based on the FiveWin codebase, here's what you need to check:

Correct Usage Pattern (from samples/graphics/gdiplus3.prg:58-69):

Code (harbour): Select all Collapse
local hdc := oWnd:getdc()
local oGraphics := Graphics():New( oWnd:hDC ) 
local oImage := GDIBmp():new("C:\fwh\bitmaps\pngs\image2.png" )

oGraphics:DrawImage( oImage, 60, 60 )

oGraphics:destroy()
oWnd:releasedc()

Common Issues:

  1. Check your DrawImage call - Your code shows oGraphics:DrawImage( ::aImages, 1, aPos ) which looks incorrect. DrawImage expects:

    • First parameter: a GDIBmp object (not an array)

    • Second parameter: nTop (numeric)

    • Third parameter: nLeft (numeric)

    • Optional: nWidth, nHeight

      Should be: oGraphics:DrawImage( ::aImages[1], nTop, nLeft )

  • Verify PNG has alpha channel - After loading, check:

    Code (harbour): Select all Collapse
    oImage1 := GDIBmp():new(, ::aNameImages[1] )
    IF !oImage1:IsAlphaChannel()
       // PNG doesn't have alpha, or loaded incorrectly
       oImage1:Set32Bits(.T.)
       oImage1:Conver24to32Alpha(.T.)  // Convert using top-left pixel as transparent color
    ENDIF
  • Resource vs File loading - If loading from resources (second parameter), ensure PNG is embedded as RCDATA (type 10), not BITMAP (type 2). For file loading, use first parameter:

    Code (harbour): Select all Collapse
    oImage1 := GDIBmp():new("c:\path\image.png")  // File
    // OR
    oImage1 := GDIBmp():new(, "MYPNG")  // Resource (must be RCDATA type 10)
  • Ensure high quality rendering:

    Code (harbour): Select all Collapse
    oGraphics := Graphics():New( hDC )
    oGraphics:SetHighQuality()  // Ensures proper alpha blending
  • The transparency should work automatically with GDI+ if the PNG has an alpha channel and you're using the correct syntax. Check your DrawImage parameters first.

    regards, saludos

    Antonio Linares
    www.fivetechsoft.com

    Continue the discussion