PNG + Transparency woes

Just starting out? Need help? Post your questions and find answers here.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

PNG + Transparency woes

Post 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
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: PNG + Transparency woes

Post by STARGÅTE »

use DrawingMode(#PB_2DDrawing_AlphaBlend)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
luis
Addict
Addict
Posts: 3894
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PNG + Transparency woes

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PNG + Transparency woes

Post 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
BERESHEIT
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: PNG + Transparency woes

Post by captain_skank »

Thanks guys.

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

cheers
User avatar
luis
Addict
Addict
Posts: 3894
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PNG + Transparency woes

Post 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).
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply