{{DISPLAYTITLE:_CLEARCOLOR}}
The {{KW|_CLEARCOLOR}} statement sets a specific color to be treated as transparent when an image is later put (via [[_PUTIMAGE]]) onto another image. 


{{PageSyntax}}
:::'''_CLEARCOLOR''' {''color&amp;''|_NONE}[, {{Parameter|Dest_Handle&amp;}}]



{{Parameters}}
* In color modes using a palette, {{Parameter|color&amp;}} is the palette index of the new transparent color value or _NONE designates no clear colors.
* If {{Parameter|color&amp;}} is not a valid palette index, an [[ERROR Codes|illegal function call]] error will occur.
* In 32-bit color modes, {{Parameter|color&amp;}} is the [[_LONG]] color value of the new transparent color.
* If {{Parameter|Dest_Handle&amp;}} is omitted, the destination is assumed to be the current write page. Zero can designate the current program screen.


''Usage:''
* If {{Parameter|Dest_Handle&amp;}} is an invalid handle, then an [[ERROR Codes|invalid handle]] error is returned. Check for bad handle values of -1 first!
* In 32-bit color modes, it simply sets the Alpha to 0 for all pixels matching the specified color.
* In the second syntax, transparency is disabled for color modes using a palette.
* '''Note:''' [[_SETALPHA]] can affect any _CLEARCOLOR alpha setting within the color range set!
* '''NOTE: 32 bit [[_NEWIMAGE]] screen page backgrounds are transparent black or [[_ALPHA]] 0. Use [[_DONTBLEND]] or [[CLS]] for opaque!'''


''Example 1:'' Using _CLEARCOLOR to &quot;mask&quot; the background color of an image.
{{CodeStart}} '' ''
{{Cl|SCREEN (statement)|SCREEN}} 13
img&amp; = {{Cl|_LOADIMAGE}}(&quot;QB64bee.png&quot;)
{{Cl|_PUTIMAGE}} , img&amp;, 0               'place actual image with background
K$ = INPUT$(1)
{{Cl|CLS}} , {{Cl|_RGB}}(255, 0, 0)             'clear screen with red background
{{Cl|_CLEARCOLOR}} {{Cl|_RGB}}(255, 255, 255), img&amp;
{{Cl|_PUTIMAGE}} , img&amp;, 0               'place image without white background
{{Cl|PRINT}} {{Cl|_CLEARCOLOR}}(img&amp;)           'displays closest clear color attribute
{{Cl|END}} '' ''
{{CodeEnd}}
: ''Note:'' The ''QB64.PNG'' image can be downloaded here: [https://dl.dropbox.com/u/8440706/QB64bee.png QB64bee.png]. Right click and Save as ''QB64bee.PNG''.


''Example 2:'' Using a _CLEARCOLOR transparency with images created on a [[_NEWIMAGE]] page. Does not require an image file.
{{CodeStart}}{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(512, 384, 32) ' screen uses handle value
{{Cl|CIRCLE}}(50, 50), 50, {{Cl|_RGB}}(128, 0, 0) ' create a red ball image
{{Cl|PAINT}}(50, 50), {{Cl|_RGB}}(255, 0, 0), {{Cl|_RGB}}(128, 0, 0)
redball = {{Cl|_NEWIMAGE}}(101, 101, 32) ' create a new image page
{{Cl|_PUTIMAGE}} , 0, redball,(0, 0)-(101, 101) ' put screen page 0 image onto redball page
{{Cl|_CLEARCOLOR}} {{Cl|_RGB}}(0, 0, 0), redball ' makes black become see-through
{{Cl|CLS}}, {{Cl|_RGB}}(0, 0, 255) ' erase original ball and create a blue background
{{Cl|DO...LOOP|DO}}
{{Cl|_PUTIMAGE| _PUTIMAGE}} ({{Cl|RND}} * 512, {{Cl|RND}} * 384), redball
{{Cl|SLEEP| SLEEP}} 1 ' one second delay
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} &lt;&gt; &quot;&quot; '' ''
{{CodeEnd}}


''Example 3:'' Fading an image with a _CLEARCOLOR background using a new page image to prevent [[_SETALPHA]] changes.
{{CodeStart}} '' ''
mainscreen = {{Cl|_NEWIMAGE}}(640, 480, 32) ' Main Screen (viewable)
{{Cl|SCREEN}} mainscreen
{{Cl|_SCREENMOVE}} {{Cl|_SCREENMOVE|_MIDDLE}}
Image1&amp; = {{Cl|_LOADIMAGE}}(&quot;QB64bee.png&quot;) '&lt;&lt;&lt;&lt;&lt;&lt; any image with one background color to clear

{{Cl|IF...THEN|IF}} Image1&amp; &lt; -1 {{Cl|THEN}} 'check loaded image handle value before using!
  {{Cl|_SOURCE}} Image1&amp;
  clr~&amp; = {{Cl|POINT}}(0, 0) 'get background color from image source
  {{Cl|_CLEARCOLOR}} clr~&amp;, Image1&amp; 'clear background color of loaded image
  NewImage1&amp; = {{Cl|_NEWIMAGE}}({{Cl|_WIDTH (function)|_WIDTH}}(Image1&amp;), {{Cl|_HEIGHT}}(Image1&amp;), 32) 'new image page
  {{Cl|_PUTIMAGE}} , Image1&amp;, NewImage1&amp; 'put image without background color on new page
  {{Cl|_FREEIMAGE}} Image1&amp; 'free loaded image from memory
{{Cl|END IF}}
{{Cl|_DEST}} mainscreen:

a&amp; = 0: d = 1
DO
  {{Cl|_LIMIT}} 10 'regulate speed of fades
  {{Cl|CLS}}
  a&amp; = a&amp; + d
  {{Cl|IF...THEN|IF}} a&amp; = 255 {{Cl|THEN}} d = -d 'reverse fade 
  {{Cl|_SETALPHA}} a&amp;, , NewImage1&amp; 'sets alpha level of all colors to fade image page in/out
  {{Cl|_PUTIMAGE}} (0, 342), NewImage1&amp; 
  {{Cl|LOCATE}} 1, 1: {{Cl|PRINT}} &quot;Alpha: &quot;; a&amp;
  {{Cl|_DISPLAY}}
{{Cl|LOOP}} {{Cl|UNTIL}} a&amp; = 0
{{Cl|END}}
{{CodeEnd}}
:''Note:'' If the _CLEARCOLOR [https://dl.dropbox.com/u/8440706/QB64bee.png QB64bee.png] background was not put onto a separate page, [[_SETALPHA]] would display it also.



{{PageSeeAlso}}
* [[_CLEARCOLOR (function)]]
* [[_SETALPHA]] {{text|(sets transparency level)}}
* [[_ALPHA]], [[_ALPHA32]] {{text|(read functions)}}
* [[Images]], [[Creating Sprite Masks]]


{{PageNavigation}}