SETALPHA: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "{{DISPLAYTITLE:_SETALPHA}}{{DISPLAYTITLE:}} The _SETALPHA statement sets the alpha channel transparency level of some or all of the pixels of an image. {{PageSyntax}} : _SETALPHA {{Parameter|alpha&}}[, {{Parameter|color1&}}][ TO {{Parameter|colour2&}}] [, {{Parameter|imageHandle&}}] {{Parameters}} * {{Parameter|alpha&}} is the new alpha level to set, ranging from 0 (transparent) to 255 (opaque). * {{Parameter|color1&}} designates the 32-bit LONG color...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_SETALPHA | {{DISPLAYTITLE:_SETALPHA}} | ||
The [[_SETALPHA]] statement sets the alpha channel transparency level of some or all of the pixels of an image. | The [[_SETALPHA]] statement sets the alpha channel transparency level of some or all of the pixels of an image. | ||
Line 7: | Line 7: | ||
{{ | {{PageParameters}} | ||
* {{Parameter|alpha&}} is the new alpha level to set, ranging from 0 (transparent) to 255 (opaque). | * {{Parameter|alpha&}} is the new alpha level to set, ranging from 0 (transparent) to 255 (opaque). | ||
* {{Parameter|color1&}} designates the 32-bit [[LONG]] color value or range of color values {{Parameter|color1&}} TO {{Parameter|colour2&}} to set the transparency. | * {{Parameter|color1&}} designates the 32-bit [[LONG]] color value or range of color values {{Parameter|color1&}} TO {{Parameter|colour2&}} to set the transparency. | ||
* If no color value or range of colors is given, the entire image's alpha is changed, including any [[_CLEARCOLOR]] settings. | * If no color value or range of colors is given, the entire image's alpha is changed, including any [[_CLEARCOLOR]] settings. | ||
* If {{Parameter|imageHandle&}} is omitted, it is assumed to be the current write page or [[_DEST|destination]] image. | * If {{Parameter|imageHandle&}} is omitted, it is assumed to be the current write page or [[_DEST|destination]] image. | ||
Line 27: | Line 27: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' Using a _SETALPHA color range to fade an image in and out while not affecting the transparent white background. | ''Example:'' Using a _SETALPHA color range to fade an image in and out while not affecting the transparent white background. | ||
{{CodeStart}} | {{CodeStart}} | ||
main = {{Cl|_NEWIMAGE}}(640, 480, 32) | main = {{Cl|_NEWIMAGE}}(640, 480, 32) | ||
{{Cl|SCREEN}} main | {{Cl|SCREEN}} main | ||
{{Cl|_SCREENMOVE}} {{Cl|_SCREENMOVE|_MIDDLE}} | {{Cl|_SCREENMOVE}} {{Cl|_SCREENMOVE|_MIDDLE}} | ||
Line 48: | Line 48: | ||
{{Cl|IF...THEN|IF}} a& = 255 {{Cl|THEN}} d = -d | {{Cl|IF...THEN|IF}} a& = 255 {{Cl|THEN}} d = -d | ||
{{Cl|_SETALPHA}} a&, 0 {{Cl|TO}} topclr~&, Image1& 'affects all colors below bright white | {{Cl|_SETALPHA}} a&, 0 {{Cl|TO}} topclr~&, Image1& 'affects all colors below bright white | ||
{{Cl|_PUTIMAGE}} (0, 342), Image1& | {{Cl|_PUTIMAGE}} (0, 342), Image1& | ||
{{Cl|LOCATE}} 1, 1: {{Cl|PRINT}} "Alpha: "; a& | {{Cl|LOCATE}} 1, 1: {{Cl|PRINT}} "Alpha: "; a& | ||
{{Cl|_DISPLAY}} | {{Cl|_DISPLAY}} | ||
{{Cl|LOOP}} {{Cl|UNTIL}} a& = 0 | {{Cl|LOOP}} {{Cl|UNTIL}} a& = 0 | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: ''Explanation:'' The [[POINT]] value minus [[_RGBA]](1, 1, 1, 0) subtracts a small amount from the bright white color value so that the top [[_SETALPHA]] color range will not affect the [[_CLEARCOLOR]] transparency of the bright white PNG background | : ''Explanation:'' The [[POINT]] value minus [[_RGBA]](1, 1, 1, 0) subtracts a small amount from the bright white color value so that the top [[_SETALPHA]] color range will not affect the [[_CLEARCOLOR]] transparency of the bright white PNG background. | ||
Line 61: | Line 61: | ||
* [[_CLEARCOLOR]] | * [[_CLEARCOLOR]] | ||
* [[_CLEARCOLOR (function)]] | * [[_CLEARCOLOR (function)]] | ||
* [[_BLEND]], [[_DONTBLEND]] | * [[_BLEND]], [[_DONTBLEND]] | ||
* [[COLOR]], [[Images]] | * [[COLOR]], [[Images]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 02:22, 24 January 2023
The _SETALPHA statement sets the alpha channel transparency level of some or all of the pixels of an image.
Syntax
Parameters
- alpha& is the new alpha level to set, ranging from 0 (transparent) to 255 (opaque).
- color1& designates the 32-bit LONG color value or range of color values color1& TO colour2& to set the transparency.
- If no color value or range of colors is given, the entire image's alpha is changed, including any _CLEARCOLOR settings.
- If imageHandle& is omitted, it is assumed to be the current write page or destination image.
Description
- In the first syntax, the alpha level of all pixels is set to alpha&.
- In the second syntax, the alpha level of all pixels matching the color color1& is set to alpha&.
- In the third syntax, the alpha level of all pixels with red, green, blue and alpha channels in the range [color1& TO color2&] are set.
- The _ALPHA setting makes a 32-bit color transparent, opaque or something in between. Zero is clear and 255 totally blocks underlying images. Use it to see through backgrounds or image colors.
- If alpha& is outside that range, an illegal function call error will occur.
- If the image specified by imageHandle& uses a palette, an invalid handle error will occur.
- If imageHandle& is an invalid handle, an illegal function call error will occur.
- NOTE: 32-bit _NEWIMAGE screen page backgrounds are transparent black or _ALPHA 0. Use _DONTBLEND or CLS for opaque.
Examples
Example: Using a _SETALPHA color range to fade an image in and out while not affecting the transparent white background.
main = _NEWIMAGE(640, 480, 32) SCREEN main _SCREENMOVE _MIDDLE Image1& = _LOADIMAGE("qb64_trans.png") '<<< PNG file with white background to hide _SOURCE Image1& clr~& = POINT(0, 0) 'find background color of image _CLEARCOLOR clr~&, Image1& 'set background color as transparent topclr~& = clr~& - _RGBA(1, 1, 1, 0) 'get topmost color range just below full white _DEST main a& = 0 d = 1 DO _LIMIT 10 'regulate speed of fade in and out CLS ', _RGB(255, 0, 0) a& = a& + d IF a& = 255 THEN d = -d _SETALPHA a&, 0 TO topclr~&, Image1& 'affects all colors below bright white _PUTIMAGE (0, 342), Image1& LOCATE 1, 1: PRINT "Alpha: "; a& _DISPLAY LOOP UNTIL a& = 0 |
- Explanation: The POINT value minus _RGBA(1, 1, 1, 0) subtracts a small amount from the bright white color value so that the top _SETALPHA color range will not affect the _CLEARCOLOR transparency of the bright white PNG background.
See also