_RGB - mkilgore/QB64pe GitHub Wiki
The _RGB function returns the closest palette attribute index (legacy SCREEN modes) OR the LONG 32-bit color value (32-bit screens).
- colorIndex~& = _RGB(red&, green&, blue&[,])
- The value returned is either the closest color attribute number or a 32-bit _UNSIGNED LONG color value.
- Return variable types must be LONG or resulting color may lose the _BLUE value.
- red& specifies the red component intensity from 0 to 255.
- green& specifies the green component intensity from 0 to 255.
- blue& specifies the blue component intensity from 0 to 255.
- Intensity values outside the valid range are clipped.
- Returns LONG 32-bit hexadecimal values from &HFF000000 to &HFFFFFFFF, always with full _ALPHA.
- When LONG values are PUT to file, the ARGB values become BGRA. Use LEFT$(MKL$(colorIndex~&), 3) to place 3 colors.
- If the imageHandle& is omitted the image is assumed to be the current destination or SCREEN page.
- Colors returned are always opaque as the transparency value is always 255. Use _ALPHA or _CLEARCOLOR to change it.
- NOTE: Default 32-bit backgrounds are clear black or _RGBA(0, 0, 0, 0). Use CLS to make the black opaque.
Example: Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values.
SCREEN 12 DIM hex32$(15) FOR...NEXT attribute = 1 TO 15 OUT &H3C7, attribute 'set color attribute to read red = INP(&H3C9) * 4 'multiply by 4 to convert intensity to 0 to 255 RGB values grn = INP(&H3C9) * 4 blu = INP(&H3C9) * 4 hex32$(attribute) = "&H" + HEX$(_RGB32(red, grn, blu)) 'always returns the 32 bit value COLOR attribute PRINT "COLOR" + STR$(_RGB(red, grn, blu)) + " = " + hex32$(attribute) 'closest attribute NEXT '' '' |
<span style="color:#0000A8;">COLOR 1 = &HFF0000A8</span> <span style="color:#00A800;">COLOR 2 = &HFF00A800</span> <span style="color:#00A8A8;">COLOR 3 = &HFF00A8A8</span> <span style="color:#A80000;">COLOR 4 = &HFFA80000</span> <span style="color:#A800A8;">COLOR 5 = &HFFA800A8</span> <span style="color:#A85400;">COLOR 6 = &HFFA85400</span> <span style="color:#A8A8A8;">COLOR 7 = &HFFA8A8A8</span> <span style="color:#545454;">COLOR 8 = &HFF545454</span> <span style="color:#5454FC;">COLOR 9 = &HFF5454FC</span> <span style="color:#54FC54;">COLOR 10 = &HFF54FC54</span> <span style="color:#54FCFC;">COLOR 11 = &HFF54FCFC</span> <span style="color:#FC5454;">COLOR 12 = &HFFFC5454</span> <span style="color:#FC54FC;">COLOR 13 = &HFFFC54FC</span> <span style="color:#FCFC54;">COLOR 14 = &HFFFCFC54</span> <span style="color:#FCFCFC;">COLOR 15 = &HFFFCFCFC</span> |
- Note: This procedure also shows how the returns from _RGB and _RGB32 differ in a non-32 bit screen mode.
- _RGBA, _RGB32, _RGBA32
- _RED, _GREEN, _BLUE
- _LOADIMAGE, _NEWIMAGE
- HEX$ 32 Bit Values, POINT
- SAVEIMAGE
- Hexadecimal Color Values
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page