The GetBValue, GetGValue, and GetRValue function retrieves an intensity value for a color component of a 32-bit red, green, blue (RGB) value.
Byte = GetBValue(rgb)
Byte = GetGValue(rgb)
Byte = GetRValue(rgb)
rgb | : 32-bit RGB value |
The return value of GetBValue is the intensity of the blue component of the specified RGB color.
The return value of GetGValue is the intensity of the green component of the specified RGB color.
The return value of GetRValue is the intensity of the red component of the specified RGB color.
The intensity value is in the range 0 through 255.
OpenW # 1
Local col%, nBlue%, nGreen%, nRed%, x%
// background color for a window
Win_1.BackColor = RGB(120, 250, 120)
// to get the whole color value
col% = Win_1.BackColor
// or for one pixel
// col% = GetPixel(Win_1.hDC , 380, 280)
Text 75, 10, "red"
Text 110, 10, "green"
Text 150, 10, "blue"
If col% > 0
nRed% = GetRValue(col)
nBlue% = GetBValue(col)
nGreen% = GetGValue(col)
Text 70, 40, nRed%
Text 110, 40, nGreen%
Text 150, 40, nBlue%
EndIf
The GetBValue, GetGValue, and GetRValue functions are actually simple byte shift functions and does not parse system colours. For example, when you assign a predefined color constant like colBtnFace (= $8000000F) you won't get the RGB-values of the color, but GetBValue(colBtnFace) = 0, GetGValue(colBtnFace) = 0, and GetRValue(colBtnFace) = 0.
In addition, these functions do not work with the ARGB colours used with GDI+; to get the individual colour components you can use the GetByten() functions as in the following example:
Local ARGB_Aquamarine = &HFF7FFFD4
Print Hex$(GetByte0(ARGB_Aquamarine)) // Alpha Value
Print Hex$(GetByte1(ARGB_Aquamarine)) // Red Value
Print Hex$(GetByte2(ARGB_Aquamarine)) // Green Value
Print Hex$(GetByte3(ARGB_Aquamarine)) // Blue Value
Print Hex$(GetRValue(ARGB_Aquamarine)) // Gets the Blue, not Red, Value
Print Hex$(GetBValue(ARGB_Aquamarine)) // Gets the Red, not Blue, Value
Print Hex$(GetGValue(ARGB_Aquamarine)) // Still gets the Green Value
GetByte0, GetByte1, GetByte2, GetByte3
{Created by Sjouke Hamstra; Last updated: 31/08/2022 by James Gaite}