ALPHA
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgAlphaGfx
- 最后更新: 2021-10-10
Put 图形语句的参数,用于选择 Alpha 混合作为传输方法
语法
Put [ target, ] [ STEP ] ( x,y ), source [ ,( x1,y1 )-( x2,y2 ) ], Alpha
Put [ target, ] [ STEP ] ( x,y ), source [ ,( x1,y1 )-( x2,y2 ) ], Alpha, alphaval参数
Alpha
必填。
alphaval
可选的 alpha 参数,范围 [0..255]。覆盖各个像素中的 alpha 值。
说明
Alpha 选择 alpha 混合作为 Put 图像的方法。如果指定了 alphaval 参数,它将覆盖每个像素的 alpha 值,且遮罩颜色(品红色)将被视为透明。此方法适用于 15、16、24 或 32 位颜色深度。
如果未指定 alphaval,Alpha 仅在 32 位颜色深度下有效,Put 将使用每个像素内嵌的 alpha 值。使用遮罩颜色的像素将被视为普通像素,并按其给定的 alpha 值绘制。
Alpha 还有另一种模式,允许将 8 位图像 Put 到 32 位图像上。在这种情况下,它将用 8 位图像的内容替换 32 位图像的 alpha 通道。
alpha 值范围为 0 到 255。alpha 值为 0 时完全不绘制图像。所有其他 alpha 值都会加 1,得到 2 到 256 的范围,然后除以 256 得到 1/128 到 1 之间的值,用于根据源像素和目标像素计算每个像素的精确值。因此,255 实际上等同于使用 Trans 位图传输模式的 Put,0 等同于不做任何操作,其他所有 alpha 值都按预期进行混合。
示例
此示例比较两种不同的 Alpha 模式,包括它们对遮罩颜色的处理方式
start GeSHi
vb
'' 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
Sleepend GeSHi
此示例展示使用 8 位图像设置 32 位 alpha 通道的特殊方法
start GeSHi
vb
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
Sleepend GeSHi
与 QB 的区别
- FreeBASIC 新增
另请参阅
Put (Graphics)TransCustom
返回 目录