QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _SETALPHA statement sets the alpha channel transparency level of some or all of the pixels of an image.


_SETALPHA alpha&[, color1&][ TO colour2&] [, imageHandle&]




Using a _SETALPHA color range to fade an image in and out while not affecting the transparent white background.

main = _NEWIMAGE(640, 480, 32) 

Image1& = _LOADIMAGE("qb64_trans.png") '<<< PNG file with white background to hide
_SOURCE Image1&
clr~& = POINT(0, 0) 'find background color of image
_CLEARCOLOR clr~&, Image1& 'set background color as transparent

topclr~& = clr~& - _RGBA(1, 1, 1, 0)  'get topmost color range just below full white
_DEST main

a& = 0
d = 1
  _LIMIT 10 'regulate speed of fade in and out
  CLS ', _RGB(255, 0, 0)
  a& = a& + d
  IF a& = 255 THEN d = -d
  _SETALPHA a&, 0 TO topclr~&, Image1& 'affects all colors below bright white
  _PUTIMAGE (0, 342), Image1& 
  LOCATE 1, 1: PRINT "Alpha: "; a&
LOOP UNTIL a& = 0 

Explanation: The POINT value minus _RGBA(1, 1, 1, 0) subtracts a small amount from the bright white color value so that the top _SETALPHA color range will not affect the _CLEARCOLOR transparency of the bright white PNG background.

See Also