image transparent


Active Member
Licensed User
Longtime User
:sign0085:I am using forelayer and drawer (imagelib.dll) to drawimage1. The transparent color on drawimage1 works fine and the background can be view through the transparent color.

However, when I draw two images, the second image overlaps the first image, then I find the first image is covered by the second image and the transparent color.

I thought it is due to I can use only onle forelayer. Any walkaround to solve that?


  • fallingball.JPG
    9.5 KB · Views: 182


B4X founder
Staff member
Licensed User
Longtime User
If you are using ImageLib, then you could draw on the back layer with transparency.
That way, many drawings can overlap without hiding each other.
Sub App_Start
      bmpSrc.New1(AppPath & "\smiley.gif") 'Loads an image from a file named smiley.gif
      rectSrc.New1(0,0,bmpSrc.Width,bmpSrc.Height) 'Same size as the image.
      drawer1.SetTransparentColor1(bmpSrc.GetPixel1(0,0)) 'Sets the transparent color to be the color of pixel (0,0) in the bitmap
       rectDest.X = 80
End Sub


Active Member
Licensed User
Longtime User
Thanks. Yes, that works for static objects.

For simulating moving objects, I was using drawer.fillrectangle with forelayer transparency to to erase the forelayer so the background can resume viewable.

If I use background layer to draw the objects, I can not resume the background image easily. As shown in the attached screen cap.

To recover the background image, Is this the only way?:
- instead of erase old image, redraw the background image on background with only the portion that is covered but old image.

:sign0137:... it would be great if the transparency setting on background layer can apply to forelayer.


  • transparent problem1.JPG
    transparent problem1.JPG
    27.7 KB · Views: 165
  • transparent problem2.JPG
    transparent problem2.JPG
    14.6 KB · Views: 169


Active Member
Licensed User
Longtime User
You could also draw on the fore layer using transparency.
That way, the background will not be altered from the drawings.

Yes, I used fore layer in first sample but I found the problem that the fore layer transparency is referring to background image only, if second image overlaps first image, the transparent part of second image will show the background image part, but not the first image part (as attached in my first message).

When I use background layer to draw overlap image, in the Repaint loop, I need to draw the background image portion, then first image, at last the second image, so I can see the second image is on top of first image (as attached).

So what I see is the transparency of forelayer will redraw background image, but instead if it would be good if the transparency is on forelayer then on backgound layer, so when I use fore layer, I don't need to redraw backgound image in the Repaint loop but got the result as in the attached image.


  • transparent problem3.JPG
    transparent problem3.JPG
    13.3 KB · Views: 161
  • fallingball.sbp
    5.7 KB · Views: 183