<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.22823-</id>
  <updated>2009-11-16T15:56:01Z</updated>
  <title>Comments for Flex Graphics Tricks Part 2: Blend Modes (http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.22823</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=22823" title="Flex Graphics Tricks Part 2: Blend Modes" />
    <published>2008-02-03T20:26:08Z</published>
    <updated>2008-02-04T14:12:30Z</updated>
    <title>Flex Graphics Tricks Part 2: Blend Modes</title>
    <summary>Here&apos;s the second installment of my mini-series on Flex graphics tricks.  The first one was about using masks with Flex objects to create interesting effects.  There are lots of cool thingsthat you can do with masks, but this time I am going to focus on graphics blend modes.</summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<p>Here's the second installment of my mini-series on Flex graphics tricks.  The <a href="http://www.insideria.com/2008/01/flex-graphics-tricks-part-1-ma.html" target="_blank">first one</a> was about using masks with Flex objects to create interesting effects.  There are lots of <a href="http://www.cynergysystems.com/blogs/page/andrewtrice?entry=fun_with_masks" target="_blank">cool things</a> that you can do with masks, but this time I am going to focus on graphics blend modes.</p>

<p>Every visible component in Flex can have a blend mode applied to it, which will change how that object is rendered on screen. The blend mode changes how the graphics of the object blend with anything that sits behind that object on the display list.  Using blend modes, you can make components or images appear only partially, or appear as color variants of other objects, or you can blend the contents of two different images dynamically at runtime.</p>

<p>There's a great explanation of what blend modes do in the <a href="http://livedocs.adobe.com/flex/2/langref/flash/display/DisplayObject.html#blendMode" target="_blank">Flex documentation</a>, and here's an excerpt from that which will help you understand exactly what is happening when a blend mode is applied.</p>

<blockquote>Flash Player applies the blendMode property on each pixel of the display object. Each pixel is composed of three constituent colors (red, green, and blue), and each constituent color has a value between 0x00 and 0xFF. Flash Player compares each constituent color of one pixel in the movie clip with the corresponding color of the pixel in the background. For example, if blendMode  is set to BlendMode.LIGHTEN, Flash Player compares the red value of the display object with the red value of the background, and uses the lighter of the two as the value for the red component of the displayed color.</blockquote>

<p>The available blend modes are:<br />
NORMAL, ADD, ALPHA, DARKEN, DIFFERENCE, ERASE, HARDLIGHT, INVERT, LAYER, LIGHTEN, MULTIPLY, OVERLAY, SCREEN, SUBTRACT </p>

<p>There is more detail on what exactly each mode does, with an example in the <a target="_blank" href="http://livedocs.adobe.com/flex/2/langref/flash/display/DisplayObject.html#blendMode">Flex documentation</a>.</p>

<p>Now, lets take a look at what we can do with these blend modes.  All of my examples will use the same images that I used in the first part of this series.   I started with these source Images:</p>

<p><a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/sourceImages.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/sourceImages.jpg" alt="sourceImages.jpg" title="Click to enlarge" width="148"/></a></p>

<p>The <a target="_blank" href="http://www.cynergysystems.com/blogs/blogs/andrew.trice/blendmodes/BlendModes.html">sample application</a> that I put together lets you experiment with the different kinds of blend modes.  Here are just a few examples.  Notice that only the non-transparent parts of the top image affect how the bottom image are displayed.  The blend mode only applies to non-transparent areas, including semi-transparent areas.  If things change in your components, that blended area also changes.  You can see in my sample application, that the blend mode changes with the component in the "Animated Image Blend Modes" tab.</p>

<p><strong>BlendMode.DIFFERENCE</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/difference.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/difference.jpg" alt="difference.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.INVERT</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/invert.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/invert.jpg" alt="invert.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.SUBTRACT</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/subtract.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/subtract.jpg" alt="subtract.jpg" title="Click to enlarge" width="148"/></a></p>

<p>Now things can really get interesting when you take Flex components and apply blend modes to them.  This technique can change the way that controls or charts are displayed, and can add a higher level of sophistication to your interface.  However, they can also be abused and make things difficult to read or just plain ugly.  </p>

<p>Here are a few examples showing what happens when you change the blend mode of a standard flex chart component:</p>

<p><strong>BlendMode.HARDLIGHT</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_hardlight.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_hardlight.jpg" alt="chart_hardlight.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.MULTIPLY</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_multiply.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_multiply.jpg" alt="chart_multiply.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.SUBTRACT</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_subtract.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_subtract.jpg" alt="chart_subtract.jpg" title="Click to enlarge" width="148"/></a></p>

<p>Now, we can take concepts from my first post, and combine graphics masks with blend modes to change how objects are rendered on top of each other.  In this example, I am using a chart as a mask on an image of the sunrise, which is overlaying the image of Chicago.  you can see that the components blend differently, based on the specified blend mode.</p>

<p><strong>BlendMode.NORMAL</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_normal.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_normal.jpg" alt="chart_mask_normal.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.DARKEN</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_darken.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_darken.jpg" alt="chart_mask_darken.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.HARDLIGHT</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_hardlight.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_hardlight.jpg" alt="chart_mask_hardlight.jpg" title="Click to enlarge" width="148"/></a></p>

<p><strong>BlendMode.OVERLAY</strong><br />
<a href="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_overlay.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/flex_graphics_tricks_part_2_bl/chart_mask_overlay.jpg" alt="chart_mask_overlay.jpg" title="Click to enlarge" width="148"/></a></p>

<p>You can play with all of my blend mode examples here:<br />
<a target="_blank" href="http://www.cynergysystems.com/blogs/blogs/andrew.trice/blendmodes/BlendModes.html">http://www.cynergysystems.com/blogs/blogs/andrew.trice/blendmodes/BlendModes.html</a></p>

<p>All of the source for this application is publicly available at:<br />
<a target="_blank" href="http://www.cynergysystems.com/blogs/blogs/andrew.trice/blendmodes/srcview/index.html">http://www.cynergysystems.com/blogs/blogs/andrew.trice/blendmodes/srcview/index.html</a></p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22823-comment:2069432</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22823" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html#comment-2069432" />
    <title>Comment from Manuel Fittko on 2009-07-29</title>
    <author>
        <name>Manuel Fittko</name>
        <uri>http://usability-online.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://usability-online.com">
        <![CDATA[<p>Hi,<br />
nice tutorial, but I have one question regarding blendMode settings in AS3. In my current project (a coverflow component, see URL) I have objects with semi-transparent bitmap reflections. I would like overlapping portions of the reflections to erase the portions of those reflections which are in the background (behind the top-level object's reflections. If you understand what I mean, is it possible to achieve this using certain BlendMode settings? I have already tried different BlendMode settings for the reflections (especially BlendMode.ERASE which I thought to be able to do the job), but none did what it was supposed to. BlendMode.ERASE just makes the whole reflection dissaper :(<br />
I have also applied BlendMode.LAYER to the objects of which the Reflections are generated. Now I am a bit confused about the whole thing...</p>

<p>Thanks for any hints! Best,<br />
Manuel Fittko</p>]]>
    </content>
    <published>2009-07-29T15:02:05Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22823-comment:2098687</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22823" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html#comment-2098687" />
    <title>Comment from Priyank on 2009-09-15</title>
    <author>
        <name>Priyank</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I too want the same thing..<br />
Anybody having any idea how to achieve this??</p>]]>
    </content>
    <published>2009-09-15T09:30:25Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22823-comment:2172575</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22823" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html#comment-2172575" />
    <title>Comment from Tyler Arehart on 2009-11-04</title>
    <author>
        <name>Tyler Arehart</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Thanks for posting. I wanted to set the blend mode on a component, and with your help I ended up with blendMode="{BlendMode.ADD}"</p>]]>
    </content>
    <published>2009-11-05T02:39:38Z</published>
  </entry>

</feed
