I have a png file with transparent background stored in Sqlite database as type picture.
I retrieve the picture to a graphics object and it is still transparent if I look at the graphics object contents in the debug window so I don’t think it has anything to do with the database steps.
When I resize it and draw it to a canvas it has a white background.
Can anyone assist me with this please?
If you can create a simple project with a sample sqlite and share by uploading the zip to the forum, someone will take a look.
What version of Xojo? What OS?
Mac Ventura latest Xojo
The problem occurs when I put the picture into a graphics object first. I only do this because I want the user to be able to adjust transparency with a slider control.
If I draw the picture straight onto the canvas or make it the backdrop it works fine.
'Print Logo from picture object
if picLogo <> nil then
'Get ratio
ratio = picLogo.Width/picLogo.Height
dim lHeight as double
dim lWidth as double
Static logoViewSize as double = 130
If ratio < 1 Then
lHeight =logoViewSize
lWidth = logoViewSize * ratio
Else
lWidth =logoViewSize
lHeight = logoViewSize / ratio
End If
'Create graphics object for logo
Dim reposLogo As New picture(picLogo.width,picLogo.height, 32)
reposLogo.Graphics.Transparency = sldTransparencyLogo.Value
reposLogo.graphics.DrawPicture(picLogo,0,0)
'Draw logo
'1. No good - graphics object displays white background
g.DrawPicture(reposLogo,0,0,lWidth,lHeight)
'2. Good - drawing directly displays transparent background (but user cannot adjust whole image transparency)
g.DrawPicture(picLogo,0,0,lWidth,lHeight)
Simply remove the depth parameter from
Dim reposLogo As New picture(picLogo.width,picLogo.height)
Thank you so much Martin. So simple but I never thought of that.
I’m very pleased.
Why do you need the second picture. Can’t you just do this?
Because there are many items drawn to the canvas.
I don’t want everything on the canvas to be transparent when the user adjusts the transparency of individual items such as the background or logo.
You could just store the transparency level beforehand in a local variable and then restore it afterwards. If you are doing this all in the Paint event it would be more efficient than using a separate picture.