Page 1 of 1

PNG + Transparency woes

Posted: Thu Dec 15, 2011 2:49 pm
by captain_skank
Hi All,

I've been playing around with .png images today with a view to creating a new front end to one of my apps.

Anyhoo when using imagegadget the image transparancy is correct.

when I use a web gadget the transparncy is a dull light blue.

And when I use a canvas gadget the transparency is black or white if i use drawalphaimage()

I'd like to use the canvasgadget as all the events i want are easy to use, however this transparancy malarchy is doing my head in.

I think i understand the white background when using the drawalphaimage because the canvasgadget defaults to a white background but how can this be changed

Cheers for any help

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0,0,0,200,200,"")
  CanvasGadget(0, 10, 10, 128, 128)
EndIf
  
 StartDrawing(CanvasOutput(0))
   DrawingMode(#PB_2DDrawing_Transparent) ; makes no difference
   DrawImage(ImageID(LoadImage(#PB_Any, "anypnghere.png")),0, 0)
 StopDrawing()

Repeat
  Event = WaitWindowEvent()
     
Until Event = #PB_Event_CloseWindow

Re: PNG + Transparency woes

Posted: Thu Dec 15, 2011 3:00 pm
by STARGĂ…TE
use DrawingMode(#PB_2DDrawing_AlphaBlend)

Re: PNG + Transparency woes

Posted: Thu Dec 15, 2011 3:03 pm
by luis
I don't have experience with the canvasgadget yet, so I could be wrong.

For the background color you can do, inside startdrawing():

Box(0,0,128,128,#Red) ; to make it red

For the alpha, #PB_2DDrawing_Transparent is only used for text, so it's wrong in your case.

#PB_2DDrawing_AlphaBlend instead seems to work, even if the help says it's only for imageoutput, but maybe it's a case of docs not updated.

Re: PNG + Transparency woes

Posted: Thu Dec 15, 2011 3:06 pm
by netmaestro
This works fine here:

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0,0,0,200,200,"")
  CanvasGadget(0, 10, 10, 128, 128)
EndIf
  
StartDrawing(CanvasOutput(0))
   Box(0,0,128,128,GetSysColor_(#COLOR_BTNFACE))
   DrawAlphaImage(ImageID(LoadImage(#PB_Any, "d:\happyface.png")),0, 0)
StopDrawing()

Repeat
  Event = WaitWindowEvent()
     
Until Event = #PB_Event_CloseWindow

PNG image to test: Image

Re: PNG + Transparency woes

Posted: Thu Dec 15, 2011 3:08 pm
by captain_skank
Thanks guys.

I didnt think about putting a coloured box on the canvas gadget first DOH!

cheers

Re: PNG + Transparency woes

Posted: Thu Dec 15, 2011 5:01 pm
by luis
awesome guy wrote: #PB_2DDrawing_AlphaBlend instead seems to work, even if the help says it's only for imageoutput, but maybe it's a case of docs not updated.
Nope, I tried other drawingmodes (#PB_2DDrawing_AlphaClip, #PB_2DDrawing_AlphaChannel) and unfortunately they don't work with canvas (as stated in the helpfile) while working with an image.
So maybe it's better to not rely on #PB_2DDrawing_AlphaBlend + canvasgadget since it's not documented (or better explicitly not supported for that target).