ALPHA32: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
''Example:'' Finding the alpha transparency level in a 32 bit screen using an [[_RGBA]]  [[_UNSIGNED]] [[LONG]] color value.
''Example:'' Finding the alpha transparency level in a 32 bit screen using an [[_RGBA]]  [[_UNSIGNED]] [[LONG]] color value.
{{CodeStart}}
{{CodeStart}}
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32)
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}})


clr~& = {{Cl|_RGBA}}(255, 0, 255, 192)
clr~& = {{Cl|_RGBA}}({{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|192|#F580B1}})
{{Cl|PRINT}} "Color:"; clr~&
{{Cl|PRINT}} {{Text|<nowiki>"Color:"</nowiki>|#FFB100}}; clr~&


{{Cl|COLOR}} clr~&
{{Cl|COLOR}} clr~&
{{Cl|PRINT}} "Alpha32:"; {{Cl|_ALPHA32}}(clr~&)
{{Cl|PRINT}} {{Text|<nowiki>"Alpha32:"</nowiki>|#FFB100}}; {{Cl|_ALPHA32}}(clr~&)


{{Cl|END}}
{{Cl|END}}
Line 40: Line 40:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1060 Featured in our "Keyword of the Day" series]
* [[_ALPHA]], [[_SETALPHA]]
* [[_ALPHA]], [[_SETALPHA]]
* [[_RGBA]], [[_RGBA32]] {{Text|(set color with alpha)}}
* [[_RGBA]], [[_RGBA32]] {{Text|(set color with alpha)}}

Latest revision as of 19:21, 24 May 2024

The _ALPHA32 function returns the alpha transparency level of a 32 bit color value.


Syntax

alpha& = _ALPHA32(color32~&)


Parameters

  • color32& is the _UNSIGNED LONG 32 bit color value used to retrieve the alpha level.
    • Color values that are set as a _CLEARCOLOR always have an alpha level of 0 (transparent).
    • _SETALPHA can set any alpha level from 0 (or fully transparent) to 255 (or opaque).
    • Normal color values that are set by _RGB or _RGB32 always have an alpha level of 255 (opaque).


Description

  • In 4-bit (16 colors) or 8-bit (256 colors) palette screens the function will return 0.
  • _RED32, _GREEN32, _BLUE32 and _ALPHA32 are all equivalent to _RED, _GREEN, _BLUE and _ALPHA but they are highly optimized and only accept a 32-bit color (RGBA) value. Using these in your code (opposed to dividing then ANDing 32-bit color values) makes code easy to read.
  • NOTE: 32 bit _NEWIMAGE screen page backgrounds are transparent black or _ALPHA 0. Use _DONTBLEND or CLS for opaque!


Examples

Example: Finding the alpha transparency level in a 32 bit screen using an _RGBA _UNSIGNED LONG color value.

SCREEN _NEWIMAGE(640, 480, 32)

clr~& = _RGBA(255, 0, 255, 192)
PRINT "Color:"; clr~&

COLOR clr~&
PRINT "Alpha32:"; _ALPHA32(clr~&)

END
Color: 3237937407
Alpha32: 192
Notes: The color value is equivalent to hexadecimal &HC0FF00FF where &HC0 equals 192. _RGB alphas are always &HFF(255).


See also



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