Level of Transparancy

BlitzMax Forums/BlitzMax Beginners Area/Level of Transparancy

.jpg has no transparancy
.png has only 1-bit 9 (on / off) transparancy, right?
but TARGA .tga has 255 levels of opacity / transparancy

how can you control the level of tranparancy in an image? I mean can you import a .tga that has 127 as transparancy, since when saved as .png in paint shop pro and the like, its either on or off. nothing in the middle for shades etc?

Wrong.

PNG as TGA have both full 8 Bit Alpha.
Main difference is that PNG has a working standard, TGA has too much optional stuff that tends to create problems.

To control the Alpha of a given pixel, you will need an app that allows this. In GIMP / Photoshop etc you normaly can not draw alpha like a normal color. But you can set the alpha on the layer blending. The only thing needed to have alpha in the end picture is that the background layer had alpha as background color and not some other.

But there are many tutorials on that for the different apps, how to use alpha on layers, alpha masks and the like :)

But to get alpha in BM you need to set blend to AlphaBlend before.

On / OFF alpha btw is called masking. This is controled through the masking color and MaskBlend.

Erm... I think you're confusing alpha and masking.

Try SetBlend ALPHABLEND, then SetAlpha 0.5 (any float between 0 and 1) before drawing images.

In GIMP / Photoshop etc you normaly can not draw alpha like a normal color.
You can edit the alpha layer directly in Photoshop.

setblend maskblend
and
setalpha 1.0
are the "default" values, yes? (I mean for un-changed stuff)

SetAlpha only works in ALPHABLEND mode. And yes, if you're using a MASKBLEND then obviously you won't be able to get soft transitions.

but that wasn't my question ;-) Maskblend is the default unless you change that setting, right? and alpha of 1.0 is default too unless changed; that was all I needed clarified :-)

I think in maskblend the default alpha is 0.5, not 1. ???

its 1.0 accoding to the tests I made ...

Default maskblend is 1.0.

Wheras with alphablend you can go like SetAlpha(0.25), and the image will be drawn at 0.25 opacity.

This may help:
images = LoadPixmapPNG("images.png")
xsize = PixmapWidth(images)
ysize = PixmapHeight(images)
images_alpha = LoadPixmapPNG("images_alpha.png")
new_images = CreatePixmap(xsize, ysize, PF_RGBA8888)
For y = 0 Until ysize
	For x = 0 Until xsize
		WritePixel new_images, x, y, (ReadPixel(images, x, y) & $FFFFFF) | ((ReadPixel(images_alpha, x, y) & $FF) Shl 24)
	Next
Next
SavePixmapPNG new_images, "new_images.png", 9
DebugLog "Done!"


Here is a program I wrote up demonstrating the various blend modes and alpha settings. It draws three overlapping circles, with the alpha channel decreasing from the center of the circle to the edge.
Strict
Graphics 800,600
Local RedOval:TImage = CreateImage(128,128,1,DYNAMICIMAGE)
Local BlueOval:TImage = CreateImage(128,128,1,DYNAMICIMAGE)
Local GreenOval:TImage = CreateImage(128,128,1,DYNAMICIMAGE)
Local Mode:Int = SOLIDBLEND
Local Alpha:Float = 1.0
Local PixMap:TPixmap
Local Color:Int = False
SetClsColor 0,0,0

'Create three circles with the alpha channel at 255 in the center and gradually
' decreasing to 0 at the edge of the circle
PixMap = LockImage(RedOval)
For Local x = -64 To 63
	For Local y = -64 To 63
		Local Distance:Float = Sqr(x*x+y*y)
		If Distance < 64
			WritePixel(Pixmap,x+64,y+64,(Int(255-Distance*4)Shl 8 + 255)Shl 16)
		Else
			WritePixel(PixMap,x+64,y+64,0)
		End If
	Next
Next
UnlockImage(RedOval)

PixMap = LockImage(GreenOval)
For Local x = -64 To 63
	For Local y = -64 To 63
		Local Distance:Float = Sqr(x*x+y*y)
		If Distance < 64
			WritePixel(Pixmap,x+64,y+64,(Int(255-Distance*4)Shl 16 + 255)Shl 8)
		Else
			WritePixel(PixMap,x+64,y+64,0)
		End If
	Next
Next
UnlockImage(GreenOval)

PixMap = LockImage(BlueOval)
For Local x = -64 To 63
	For Local y = -64 To 63
		Local Distance:Float = Sqr(x*x+y*y)
		If Distance < 64
			WritePixel(Pixmap,x+64,y+64,(Int(255-Distance*4)Shl 24 + 255))
		Else
			WritePixel(PixMap,x+64,y+64,0)
		End If
	Next
Next
UnlockImage(BlueOval)
			
'Main loop
While Not KeyHit(KEY_ESCAPE)
	Cls
	SetBlend Mode
	SetAlpha Alpha
	
	'draw the three circles overlapping
	DrawImage RedOval,100,100
	DrawImage GreenOval,164,100
	DrawImage BlueOval,132,164
	
	SetBlend SOLIDBLEND
	SetAlpha 1.0
	Select Mode
		Case SOLIDBLEND
			DrawText "Mode: SOLIDBLEND",10,400
		Case MASKBLEND
			DrawText "Mode: MASKBLEND",10,400
		Case ALPHABLEND
			DrawText "Mode: ALPHABLEND",10,400
		Case LIGHTBLEND
			DrawText "Mode: LIGHTBLEND",10,400
		Case SHADEBLEND
			DrawText "Mode: SHADEBLEND",10,400
	End Select
	
	DrawText "Alpha: "+alpha,10,430
	
	DrawText "M: Change Blend Mode",10,500
	DrawText "B: Toggle Background Color",10,520
	DrawText "Up/Down Arrows: Increase/Decrease Alpha",10,540
	
	Flip
	'M: Change Blend Mode
	If KeyHit(KEY_M)
		Select mode
			Case SOLIDBLEND
				Mode = MASKBLEND
			Case MASKBLEND
				Mode = ALPHABLEND
			Case ALPHABLEND
				Mode = LIGHTBLEND
			Case LIGHTBLEND
				Mode = SHADEBLEND
			Case SHADEBLEND
				Mode = SOLIDBLEND
		End Select
	End If
	
	'B: Change ackground color
	If KeyHit(KEY_B)
		If Color
			Color = False
			SetClsColor 0,0,0
		Else
			Color = True
			SetClsColor 255,255,255
		End If
	End If
	
	'Up/Down: Change Alpha
	If KeyHit(KEY_UP) And Alpha < 1.0 Then Alpha :+ .1
	If KeyHit(KEY_DOWN) And Alpha > 0.0 Then Alpha :- .1
Wend