Page 1 of 1

gdi transparent question

Posted: Sat Nov 08, 2025 4:59 pm
by Silvio.Falconi

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 ?


Re: gdi transparent question

Posted: Sun Nov 09, 2025 9:34 am
by Antonio Linares

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: Select all | Expand

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 )

  2. Verify PNG has alpha channel - After loading, check:

    Code: Select all | Expand

    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
  3. 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: Select all | Expand

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

    Code: Select all | Expand

    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.