COLOR
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgColor
- 最后更新: 2023-07-09
设置用于控制台输出和文本图形输出的前景色/背景色
语法
declare function Color ( byval foreground as ulong , byval background as ulong ) as ulong用法
Color [foreground] [, background]
result = Color [( [foreground] [, background] )]参数
foreground
要设置的前景色
background
要设置的背景色
返回值
返回一个32位值,低字包含当前前景色,高字包含当前背景色。
在高彩/真彩模式下,仅返回前景色,占用全部32位。如需返回当前图形模式颜色(前景色和背景色),请参阅 ScreenControl。
新旧颜色值可在同一时间获取和设置。
说明
Color 语句设置当前前景色和/或背景色。当你不向 Circle、Draw、Line (Graphics)、Cls、Paint、Print、PReset 和 PSet 指定颜色时,它们将使用此函数最后设置的颜色(如适用)。Color 接受的颜色值取决于当前图形模式。
| 模式 | 含义 |
|---|---|
| 1 | 前景色为屏幕颜色(范围0-15)。背景色为要使用的模拟CGA调色板:0(绿、红、棕)、1(青、品红、白)、2(与0相同,但使用亮色)或3(与1相同,但使用亮色) |
| 2, 11 | 前景色为当前调色板中的颜色索引(范围0-1)。背景色为当前调色板中的颜色索引(范围0-1)。 |
| 7, 8 | 前景色为当前调色板中的颜色索引(范围0-15)。背景色为当前调色板中的屏幕颜色索引(范围0-15)。 |
| 9 | 前景色为当前调色板中的颜色索引(范围0-63)。背景色为当前调色板中的屏幕颜色索引(范围0-63)。 |
| 12 | 前景色为当前调色板中的颜色索引(范围0-15)。背景色为当前调色板中的颜色索引(范围0-15)。 |
| 13及以上 | 前景色为当前调色板中的颜色索引(范围0-255)。背景色为当前调色板中的颜色索引(范围0-255)。 |
如果使用超过8bpp的颜色深度,前景色和背景色为 &hAARRGGBB 格式的直接 RGB 颜色值,其中 AA、RR、GG 和 BB 分别为alpha、红、绿和蓝分量,范围为 &h00-&hFF(十进制0-255)。在高彩/真彩模式下,可使用 RGB 或 RGBA 宏来获取有效颜色值。
进入 Screen (Graphics) 模式时会自动设置默认调色板。
示例
start GeSHi
vb
' Sets 320x240 in 32bpp color depth
Screen 14, 32
' Sets orange foreground and dark blue background color
Color RGB(255, 128, 0), RGB(0, 0, 64)
' Clears the screen to the background color
Cls
' Prints "Hello World!" in the middle of the screen
Locate 15, 14
Print "Hello World!"
Sleepend GeSHi
start GeSHi
vb
Dim c As Ulong
'retrieve current color values
c = Color()
'extract color values from c using LOWORD and HIWORD
Print "Console colors:"
Print "Foreground: " & LoWord(c)
Print "Background: " & HiWord(c)end GeSHi
start GeSHi
vb
' In 32-bit color depth, Function Color() returns only the foreground color
#include "fbgfx.bi"
'' screencontrol expects integer/uinteger
Dim As Long fgcolor, bkcolor
ScreenRes 500, 500, 32
Width 500\8, 500\16
Color &HFFFF00, &H0000FF
Cls
Print "From Function Color():"
Print " Foreground Color: "; Hex(Color(), 8)
Print
ScreenControl FB.GET_COLOR, fgcolor, bkcolor
Print "From Sub ScreenControl():"
Print " Foreground Color: "; Hex(fgcolor, 8)
Print " Background Color: "; Hex(bkcolor, 8)
Sleepend GeSHi
与 QB 的差异
- QB 不支持直接颜色模式。
- 无边框参数。
另请参阅
RGBRGBALOWORDHIWORDLocatePaletteScreen (Graphics)
返回 目录