RGBA: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
* The [[_ALPHA|''alpha&'']] value can be set to make the color transparent (0), opaque (255) or somewhere in between.
* The [[_ALPHA|''alpha&'']] value can be set to make the color transparent (0), opaque (255) or somewhere in between.
* Parameter values outside of the 0 to 255 range are clipped.
* Parameter values outside of the 0 to 255 range are clipped.
* Returns [[LONG]] 32-bit hexadecimal values from '''&H00{{text|00|red}}{{text|00|green}}{{text|00|blue}}''' to '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|FF|blue}}''' with varying [[_ALPHA]] transparency.
* Returns [[LONG]] 32-bit hexadecimal values from '''&H00{{Text|00|red}}{{Text|00|green}}{{Text|00|blue}}''' to '''&HFF{{Text|FF|red}}{{Text|FF|green}}{{Text|FF|blue}}''' with varying [[_ALPHA]] transparency.
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|colorIndex~&}}), 3) to place 3 colors.
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|colorIndex~&}}), 3) to place 3 colors.
* If {{Parameter|imageHandle&}} is omitted, the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page.
* If {{Parameter|imageHandle&}} is omitted, the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page.
Line 25: Line 25:
{{CodeStart}}
{{CodeStart}}
scrn& = {{Cl|_NEWIMAGE}}(400, 400, 32)
scrn& = {{Cl|_NEWIMAGE}}(400, 400, 32)
{{Cl|SCREEN (statement)|SCREEN}} scrn&
{{Cl|SCREEN}} scrn&
fnt& = {{Cl|_LOADFONT}}("C:\WINDOWS\FONTS\ARIAL.TTF", 26)
fnt& = {{Cl|_LOADFONT}}("C:\WINDOWS\FONTS\ARIAL.TTF", 26)
{{Cl|_FONT}} fnt&
{{Cl|_FONT}} fnt&
Line 36: Line 36:
{{Cl|END}}
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{small|Code by Unseen Machine}}
{{Small|Code by Unseen Machine}}
''Explanation:'' [[_PRINTSTRING]] allows text or font colors to be alpha blended in 32 bit screens.
''Explanation:'' [[_PRINTSTRING]] allows text or font colors to be alpha blended in 32 bit screens.


Line 46: Line 46:
* [[_PRINTSTRING]]
* [[_PRINTSTRING]]
* [[HEX$ 32 Bit Values]], [[POINT]]
* [[HEX$ 32 Bit Values]], [[POINT]]
* [[SAVEIMAGE]]
* [[SaveImage SUB]]
* [http://www.w3schools.com/html/html_colornames.asp Hexadecimal Color Values]
* [http://www.w3schools.com/html/html_colornames.asp Hexadecimal Color Values]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 20:04, 5 January 2024

The _RGBA function returns the closest palette index (legacy SCREEN modes) OR the 32-bit LONG color value (32-bit screens).


Syntax

colorIndex~& = _RGBA(red&, green&, blue&, alpha&[, imageHandle&])


  • 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 the 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.
  • The alpha& value can be set to make the color transparent (0), opaque (255) or somewhere in between.
  • Parameter values outside of the 0 to 255 range are clipped.
  • Returns LONG 32-bit hexadecimal values from &H00000000 to &HFFFFFFFF with varying _ALPHA transparency.
  • When LONG values are PUT to file, the ARGB values become BGRA. Use LEFT$(MKL$(colorIndex~&), 3) to place 3 colors.
  • If imageHandle& is omitted, the image is assumed to be the current destination or SCREEN page.
  • Allows the blending of pixel colors red, green and blue to create any of 16 million colors.
  • NOTE: Default 32-bit backgrounds are clear black or _RGBA(0, 0, 0, 0). Use CLS to make the black opaque.


Examples

Example: Setting a font's background color alpha to clear to overlay a second text color.

scrn& = _NEWIMAGE(400, 400, 32)
SCREEN scrn&
fnt& = _LOADFONT("C:\WINDOWS\FONTS\ARIAL.TTF", 26)
_FONT fnt&
X% = 20
Y% = 20
COLOR _RGB(255, 255, 255), _RGB(0, 0, 0) 'Foreground set to WHITE background to BLACK
_PRINTSTRING (X%, Y%), "Hello World"
COLOR _RGB(255, 0, 0), _RGBA(0, 0, 0, 0) 'Foreground set to RED background to TRANSPARENT BLACK
_PRINTSTRING (X% + 2, Y% + 2), "Hello World"
END
Code by Unseen Machine

Explanation: _PRINTSTRING allows text or font colors to be alpha blended in 32 bit screens.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link