RGB
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgRgb
- 最后更新: 2021-10-13
计算高彩/真彩模式的有效颜色值
语法
#define RGB(r,g,b) culng((cubyte(r) shl 16) or (cubyte(g) shl 8) or cubyte(b) or (&hFF000000ul))用法
result = RGB(red, green, blue)参数
red
红色分量值
green
绿色分量值
blue
蓝色分量值
返回值
合并后的颜色值。
说明
red、green 和 blue 是范围 0-255 的分量。
RGB 函数可用于计算在高彩/真彩模式下使用的有效颜色值。它返回一个无符号长整数,格式为 &hAARRGGBB,其中 RR、GG 和 BB 等于以十六进制格式传递给此函数的值。AA 是隐式 alpha 值,自动设置为 &hFF(不透明)。
可以使用 And 和 Shr 的组合从颜色值中检索红、绿、蓝和 alpha 值。下面的第二个示例展示了如何 #Define 和使用宏来实现这一点。
Windows API 程序员注意:Windows 参考中名为 RGB 的宏在 FB 的 Windows 头文件中已重命名为 BGR 以避免冲突。
示例
另见 Put (Graphics) 示例。
start GeSHi
ScreenRes 640,480,32 '32 bit color
Line(0,0)-(319,479), RGB(255,0,0) 'draws a bright red box on the left side of the window
Line(639,0)-(320,479), RGB(0,0,255) 'draws a bright blue box on the right side of the window
Sleep 'wait before exitingend GeSHi
start GeSHi
vb
'' setting and retrieving Red, Green, Blue and Alpha values
#define RGBA_R( c ) ( CULng( c ) Shr 16 And 255 )
#define RGBA_G( c ) ( CULng( c ) Shr 8 And 255 )
#define RGBA_B( c ) ( CULng( c ) And 255 )
#define RGBA_A( c ) ( CULng( c ) Shr 24 )
Dim As UByte r, g, b, a
Dim As ULong col = RGB(128, 192, 64)
Print Using "Color: _&H\ \"; Hex(col, 8)
r = RGBA_R( col )
g = RGBA_G( col )
b = RGBA_B( col )
a = RGBA_A( col )
Print
Print Using "Red: _&H\\ = ###"; Hex(r, 2); r
Print Using "Green: _&H\\ = ###"; Hex(g, 2); g
Print Using "Blue: _&H\\ = ###"; Hex(b, 2); b
Print Using "Alpha: _&H\\ = ###"; Hex(a, 2); aend GeSHi
版本
- fbc 1.08.0 之前:
方言差异
- 在 -lang qb 方言中不可用,除非使用别名
__Rgb引用。
与 QB 的区别
- FreeBASIC 新增
另请参阅
RGBAColor#Define
返回 目录