Page 1 of 1

Transparent Image has white background

Posted: Thu Aug 14, 2025 8:29 pm
by KianV
Does anyone have any idea what could be causing this behaviour ?
I am trying to create a transparent image on which to write some text which can then be turned upside down.
When I added in the text it always appeared on a white background, so I stripped out that part, just leaving the image empty.

The following code snippet:

Code: Select all

CreateImage(277,200,200,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(#finalimage))
DrawingMode(#PB_2DDrawing_Transparent)
DrawImage(ImageID(277),0,0)
still just outputs a white box onto the background (finalimage).
I can draw shapes onto image 277 and they still have a white background.
Using ' DrawAlphaImage(ImageID(277),0,0) ' does not show anything on the final image.
I have been using lots of bad words at my computer and would appreciate any help as to the possible cause.

Re: Transparent Image has white background

Posted: Thu Aug 14, 2025 8:35 pm
by miso
Hello KianV!

There were some changes. Please try this. (Not tested, I hope I wrote everything right.)
(Im sure its not, as 277 is empty.

Code: Select all

CreateImage(277,200,200,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(#finalimage))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawAlphaImage(ImageID(277),0,0)
StopDrawing()

Re: Transparent Image has white background

Posted: Thu Aug 14, 2025 8:38 pm
by User_Russian
KianV wrote: Thu Aug 14, 2025 8:29 pmThe following code snippet:
No problem. The image is transparent.

Code: Select all

#finalimage=0
CreateImage(#finalimage,200,200,32,#PB_Image_Transparent)
CreateImage(277,200,200,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(#finalimage))
DrawingMode(#PB_2DDrawing_Transparent)
DrawImage(ImageID(277),0,0)
StopDrawing()
ShowLibraryViewer("Image", #finalimage)
CallDebugger

Re: Transparent Image has white background

Posted: Thu Aug 14, 2025 9:04 pm
by miso
Ok, this is a working example. Save it to disk, as it will create the 2 images as png to see the result.

Code: Select all

UsePNGImageEncoder()

#finalimage=0
CreateImage(#finalimage,200,200,32,#PB_Image_Transparent)


CreateImage(277,200,200,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(277))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight(),RGBA(0,0,0,0))
Circle(100,100,25,RGBA(255,0,0,255))

StopDrawing()

StartDrawing(ImageOutput(#finalimage))
DrawingMode(#PB_2DDrawing_Transparent)
DrawAlphaImage(ImageID(277),20,20)
DrawAlphaImage(ImageID(277),50,50)

StopDrawing()


SaveImage(0,"0.png",#PB_ImagePlugin_PNG)
SaveImage(277,"277.png",#PB_ImagePlugin_PNG)

Re: Transparent Image has white background

Posted: Fri Aug 15, 2025 5:40 pm
by KianV
Thankyou @miso and @User_Russian,
After many sweary dead-ends I took a different approach. I had to move the code earlier in the program and it worked - after a fashion.
Whenever I tried to create a blank image I got the white background, even though other transparent images are created elsewhere and do not have a problem. With this in mind I loaded an image with the section of background it was to be printed on and drew the text onto that. I moved a few things about so that they would not cover the text. This was then drawn back onto the final image.
There must be something in the rest of the program which is causing this behaviour, but there are over 3000 lines to go through.
If I ever discover the source of the problem I shall post it here.
Thanks again.
Kian

Re: Transparent Image has white background

Posted: Fri Aug 15, 2025 5:46 pm
by miso
I now always clear the alphachannel when a new sprite or image is created. Because that way it does not matter, how it is started. Blank or filled with a color. Might be an extra step, but that way I dont have to follow future changes or differences between images/sprites.

Code: Select all

DrawingMode(#PB_2DDrawing_AllChannel)
Box(0,0,OutputWidth(),OutputHeight(),RGBA(0,0,0,0))
DrawingMode(#PB_2DDrawing_Alphablend)
At the moment I also work with fonts and images.