Difference between revisions of "RGB"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 11: Line 11:
 
* Intensity values outside the valid range are clipped.
 
* Intensity values outside the valid range are clipped.
 
* Returns [[LONG]] 32 bit hexadecimal values from '''&HFF{{text|00|red}}{{text|00|green}}{{text|00|blue}}''' to '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|FF|blue}}''' with full [[_ALPHA]] only.
 
* Returns [[LONG]] 32 bit hexadecimal values from '''&HFF{{text|00|red}}{{text|00|green}}{{text|00|blue}}''' to '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|FF|blue}}''' with full [[_ALPHA]] only.
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]](colorvalue&), 3) to place 3 bytes.
+
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]](colorvalue&), 3) to place 3 colors.
 
* If the ''image_handle'' is omitted the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page.
 
* If the ''image_handle'' is omitted the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page.
 
* Colors returned are ALWAYS opaque as the transparency value is always 255! Use [[_ALPHA]] or [[_CLEARCOLOR]] to change it.
 
* Colors returned are ALWAYS opaque as the transparency value is always 255! Use [[_ALPHA]] or [[_CLEARCOLOR]] to change it.

Revision as of 17:30, 3 July 2012

The _RGB function returns the closest palette attribute index OR the LONG 32 bit color value in 32 bit screens only.


colorindex& = _RGB(red, green, blue[, image_handle])


  • The value returned is either the closest color attribute number or a 32 bit LONG color value. Variable types MUST be LONG!
  • 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 with full _ALPHA only.
  • When LONG values are PUT to file, the ARGB values become BGRA. Use LEFT$(MKL$(colorvalue&), 3) to place 3 colors.
  • If the image_handle 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 attribute = 1 TO 15 OUT &H3C7, attribute 'set color attribute to read red = INP(&H3C9) * 4 'convert port setting to 32 bit 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

Note: This procedure also shows how the returns from _RGB and _RGB32 differ in a non-32 bit screen mode.


See also



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page