PAINT
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgPaint
- 最后更新: 2023-07-09
PAINT — 对有边界区域进行填充
语法
vb
Paint [target,] [STEP] (x, y) [, [paint] [, [border_color]]]参数
| 参数 | 说明 |
|---|---|
target | 可选。要填充的 Get/Put 缓冲区。如果省略,使用当前工作页面。 |
STEP | 可选。表示 (x, y) 坐标相对于最后一次图形光标位置。 |
(x, y) | 填充开始的像素坐标。 |
paint | 可选。数字颜色值,或指定磁贴图案的字符串。默认为当前前景颜色。 |
border_color | 可选。填充停止的边界颜色。默认为当前背景颜色。 |
说明
PAINT 是执行填充(也称为"油漆桶"操作)的图形命令。它填充由指定颜色限定的区域。
填充从 (x, y) 开始。如果指定了 STEP,坐标相对于最后一次图形光标位置。坐标也受 Window 和/或 View (Graphics) 设置的任何自定义坐标系影响;View 设置的裁剪区域会被应用。
数字填充值:
如果 paint 是数字,它被视为与 Color 语句相同格式的颜色,并使用该颜色执行实心填充。
字符串填充值(磁贴图案):
如果 paint 是字符串,该区域将用重复的 8×8 像素磁贴图案填充。字符串必须包含原始像素数据,其大小取决于当前颜色深度:
| 颜色深度 | 所需字符串大小 |
|---|---|
| 1, 2, 4, 8 bpp | 8 × 8 = 64 字节 |
| 15 或 16 bpp | (8 × 8) × 2 = 128 字节 |
| 24 或 32 bpp | (8 × 8) × 4 = 256 字节 |
像素按行存储。如果字符串比所需短,缺少的像素被视为 0。
边界行为:
填充继续直到遇到与 border_color 匹配的像素为止。如果省略 border_color,使用当前背景颜色。
警告: 如果边界是用透明颜色(使用
GFX_ALPHA_PRIMITIVES标志)绘制的,边界像素混合后的最终颜色可能会产生"漏洞",导致填充溢出边界。不建议使用透明颜色绘制边界。
示例
示例 1 — 简单填充
vb
' Draw a white circle and fill its interior with blue
Screen 13
Circle (160, 100), 30, 15
Paint (160, 100), 1, 15
Sleep示例 2 — 磁贴图案填充
vb
' Select screen bit depth (try 8, 16, or 32)
Const bit_depth = 8
' Helper: return one pixel as a string for the current bit depth
Function paint_pixel( ByVal c As ULong, ByVal bit_depth_ As Integer ) As String
If bit_depth_ <= 8 Then
Function = Chr( CUByte(c) )
ElseIf bit_depth_ <= 16 Then
Function = MKShort( c Shr 3 And &h1f Or _
c Shr 5 And &h7e0 Or _
c Shr 8 And &hf800 )
ElseIf bit_depth_ <= 32 Then
Function = MKL(c)
End If
End Function
ScreenRes 320, 200, bit_depth
Dim As ULong c, c1, c2, cb
Dim As String paint_pattern = ""
If bit_depth <= 8 Then
c1 = 7 ' pattern color 1 (light gray)
c2 = 8 ' pattern color 2 (dark gray)
cb = 15 ' border color (white)
Else
c1 = RGB(192, 192, 192)
c2 = RGB(128, 128, 128)
cb = RGB(255, 255, 255)
End If
' Build an 8x8 checkerboard pattern
For y As UInteger = 0 To 7
For x As UInteger = 0 To 7
If (x \ 4 + y \ 4) Mod 2 > 0 Then
c = c1
Else
c = c2
End If
paint_pattern = paint_pattern + paint_pixel(c, bit_depth)
Next x
Next y
' Draw a circle with the border color
Circle (160, 100), 50, cb, , , 1.0
' Flood-fill the circle with the tile pattern
Paint (160, 100), paint_pattern, cb
Sleep与 QB 的区别
target参数是 FreeBASIC 扩展。- 在 QB 中,填充图案始终为 8 位宽,最多 64 字节高。在 FreeBASIC 中,图案始终为 8 像素宽(与颜色深度无关),始终为 8 像素高。
- QB 支持的背景色参数在 FreeBASIC 中不受支持。
另请参阅
- KeyPgScreengraphics —
Screen(图形) - KeyPgCircle —
Circle - KeyPgPset —
PSet