TRANS
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgTransGfx
- 最后更新: 2020-12-19
Put 图形语句的参数,选择透明背景作为位图传输方法
语法
Put [ target, ] [ STEP ] ( x,y ), source [ ,( x1,y1 )-( x2,y2 ) ], Trans参数
Trans
必填。
说明
Trans 选择透明背景作为图像缓冲区位图传输的方法。这与 PSET 方法类似,但包含遮罩颜色的像素将被跳过。
对于 8 位颜色图像,遮罩颜色是调色板索引 0。对于 16/32 位颜色图像,遮罩颜色是品红色,即 RGB(255, 0, 255)。在 32 位图像中检查遮罩颜色时,alpha 值将被忽略。
注意:对于 32 位图像,像素的 alpha 值可能会被更改为 0。这是出于效率考虑。要保留 alpha 值,可以使用自定义混合函数,如下面第二个示例所示。
示例
start GeSHi
vb
'' set up a screen: 320 * 200, 16 bits per pixel
ScreenRes 320, 200, 16
'' set up an image with the mask color as the background.
Dim img As Any Ptr = ImageCreate( 32, 32, RGB(255, 0, 255) )
Circle img, (16, 16), 15, RGB(255, 255, 0), , , 1, f
Circle img, (10, 10), 3, RGB( 0, 0, 0), , , 2, f
Circle img, (23, 10), 3, RGB( 0, 0, 0), , , 2, f
Circle img, (16, 18), 10, RGB( 0, 0, 0), 3.14, 6.28
'' Put the image with PSET (gives the exact contents of the image buffer)
Draw String (110, 50 - 4), "Image put with PSET"
Put (60 - 16, 50 - 16), img, PSet
'' Put the image with TRANS
Draw String (110, 150 - 4), "Image put with TRANS"
Put (60 - 16, 150 - 16), img, Trans
'' free the image memory
ImageDestroy img
'' wait for a keypress
Sleepend GeSHi
start GeSHi
vb
Function trans32 ( ByVal source_pixel As ulong, ByVal destination_pixel As ulong, ByVal parameter As Any Ptr ) As ulong
'' returns the source pixel
'' unless it is &hff00ff (magenta), then return the destination pixel
If (source_pixel And &hffffff) <> &hff00ff Then
Return source_pixel
Else
Return destination_pixel
End If
End Function
'' set up a screen: 320 * 200, 16 bits per pixel
ScreenRes 320, 200, 32
'' set up an image with the mask color as the background.
Dim img As Any Ptr = ImageCreate( 32, 32, RGB(255, 0, 255) )
Circle img, (16, 16), 15, RGB(255, 255, 0), , , 1, f
Circle img, (10, 10), 3, RGB( 0, 0, 0), , , 2, f
Circle img, (23, 10), 3, RGB( 0, 0, 0), , , 2, f
Circle img, (16, 18), 10, RGB( 0, 0, 0), 3.14, 6.28
'' Put the image with PSET (gives the exact contents of the image buffer)
Draw String (110, 50 - 4), "Image put with PSET"
Put (60 - 16, 50 - 16), img, PSet
'' Put the image with TRANS
Draw String (110, 100 - 4), "Image put with TRANS"
Put (60 - 16, 100 - 16), img, Trans
'' Put the image with TRANS
Draw String (110, 150 - 4), "Image put with trans32"
Put (60 - 16, 150 - 16), img, Custom, @trans32
'' free the image memory
ImageDestroy img
'' wait for a keypress
Sleepend GeSHi
与 QB 的区别
- FreeBASIC 新增
另请参阅
Put (Graphics)Custom
返回 目录