{{fbdoc item="title" value="ALPHA"}}----
Parameter to the ##[[KeyPgPutgraphics Put]]## graphics statement which selects alpha blending as the method

{{fbdoc item="syntax"}}##
	**Put** [ //target//, ] [ STEP ] ( //x//,//y// ), //source// [ ,( //x1//,//y1// )-( //x2//,//y2// ) ], **Alpha**
	**Put** [ //target//, ] [ STEP ] ( //x//,//y// ), //source// [ ,( //x1//,//y1// )-( //x2//,//y2// ) ], **Alpha**, //alphaval//
##
{{fbdoc item="param"}}
	##**Alpha**##
		Required.
	##//alphaval//##
		Optional alpha parameter in the range [0..255].  Overrides alpha values in individual pixels.

{{fbdoc item="desc"}}
	##**Alpha**## selects alpha blending as the method for ##[[KeyPgPutgraphics Put]]##ting an image.  If the ##//alphaval//## parameter is specified, it overrides the alpha value of each pixel, and the mask color (magenta) will be treated as transparent.  This works in 15, 16, 24, or 32-bit color depths.

	If ##//alphaval//## is not specified, ##**Alpha**## will only work in 32-bit color depth, and ##[[KeyPgPutgraphics Put]]## will use the alpha value embedded within each pixel.  Pixels using the mask color will be treated as normal, and drawn with their given alpha value.
	
	##**Alpha**## also has another mode which allows an 8-bit image to be ##[[KeyPgPutgraphics Put]]## on top of a 32-bit image.  In this case, it will replace the alpha channel of the 32-bit image with the contents of the 8-bit image.

	    Alpha values range between 0 and 255.  An alpha value of 0 will not draw the image at all.  All other alpha values are incremented by 1 to get a range between 2 and 256, and the result is then divided by 256 to get a value between 1/128 and 1, which is used to calculate the exact value of each pixel from the source and destination pixels.  Thus, 255 is practically equivalent to drawing using Put with Trans blitting mode, 0 is equivalent to doing nothing at all, and all the other alpha values blend is expected.

{{fbdoc item="ex"}}
	This example compares the two different ##**Alpha**## modes, including how they react to the mask color
{{fbdoc item="filename" value="examples/manual/gfx/put-alpha.bas"}}%%(freebasic)
'' Set up a 32-bit screen
screenres 320, 200, 32

'' Draw checkered background
for y as integer = 0 to 199
	for x as integer = 0 to 319
	    pset (x, y), iif((x shr 2 xor y shr 2) and 1, rgb(160, 160, 160), rgb(128, 128, 128))
	next x
next y

'' Make image sprite for Putting
dim img as any ptr = imagecreate(32, 32, rgba(0, 0, 0, 0))
for y as single = -15.5 to 15.5
	for x as single = -15.5 to 15.5
	    dim as integer r, g, b, a
	    if y <= 0 then
	        if x <= 0 then
	            r = 255: g = 0: b = 0   '' red
	        else
	            r = 0: g = 0: b = 255   '' blue
	        end if
	    else
	        if x <= 0 then
	            r = 0: g = 255: b = 0   '' green
	        else
	            r = 255: g = 0: b = 255 '' magenta (transparent mask color)
	        end if
	    end if
	    a = 255 - (x ^ 2 + y ^ 2)
	    if a < 0 then a = 0': r = 255: g = 0: b = 255
	    pset img, (15.5 + x, 15.5 - y), rgba(r, g, b, a)
	next x
next y

'' Put with single Alpha value, Trans for comparison
draw string (32, 10), "Single alpha"
put (80 - 16,  50 - 16), img, alpha, 64
put (80 - 16, 100 - 16), img, alpha, 192
put (80 - 16, 150 - 16), img, trans

'' Put with full Alpha channel
draw string (200, 10), "Full alpha"
put (240 - 16, 100 - 16), img, alpha

'' Free the image memory
imagedestroy img

'' Wait for a keypress
sleep
%%
{{image class="center" title="Put Alpha example output"  url="/images/AL0.PNG"}}

	This example shows the special method for setting a 32-bit alpha channel using an 8-bit image
{{fbdoc item="filename" value="examples/manual/gfx/put-alpha-8bit.bas"}}%%(freebasic)
dim as any ptr img8, img32
dim as integer x, y, i

'' Set up an 8-bit graphics screen
screenres 320, 200, 8
for i = 0 to 255
	palette i,  i, i, i
next i
color 255, 0

'' Create an 8-bit image
img8 = imagecreate(64, 64, 0,  8)
for y = 0 to 63
	for x = 0 to 63
	    dim as single x2 = x - 31.5, y2 = y - 31.5
	    dim as single t = sqr(x2 ^ 2 + y2 ^ 2) / 5
	    pset img8, (x, y), sin(t) ^ 2 * 255
	next x
next y

draw string (16, 4), "8-bit Alpha sprite"
put (16, 16), img8
sleep


'' Set up a 32-bit graphics screen
screenres 320, 200, 32
for y = 0 to 199
	for x = 0 to 319
	    pset (x, y), iif(x - y and 3, rgb(160, 160, 160), rgb(128, 128, 128))
	next x
next y

'' Create a 32-bit, fully opaque sprite
img32 = imagecreate(64, 64, 0, 32)
for y = 0 to 63
	for x = 0 to 63
	    pset img32, (x, y), rgb(x * 4, y * 4, 128)
	next x
next y

draw string (16, 4), "Original Alpha channel"
put (16, 16), img32, alpha

'' Put a new alpha channel using the 8-bit image
put img32, (0, 0), img8, alpha

draw string (16, 104), "New Alpha channel"
put (16, 116), img32, alpha

''Free the memory for the two images
imagedestroy img8
imagedestroy img32

sleep%%
{{image class="center" title="Put Alpha example 2 output" url="/images/AL1.PNG" }}

{{fbdoc item="diff"}}
	- New to ""FreeBASIC""

{{fbdoc item="see"}}
	- ##[[KeyPgPutgraphics Put (Graphics)]]##
	- ##[[KeyPgTransGfx Trans]]##
	- ##[[KeyPgCustomgfx Custom]]##
	
{{fbdoc item="back" value="CatPgGfx2D|2D Drawing Functions"}}