Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't forget to unpremultiply the colors before changing the alpha, and re-premultiply them afterward.</p> <p>Premultiplied color (often called “premultiplied alpha”, which is misleading) means that the color components are stored already multiplied by the alpha, to ease compositing. The usual compositing (source-over) operation looks like this:</p> <pre><code>result = (source.rgb * source.a) + (destination.rgb * (1.0 - destination.a)); </code></pre> <p>Premultiplication means that the first multiplication is already done, so it can be skipped:</p> <pre><code>result = source.rgb + (destination.rgb * (1.0 - destination.a)); </code></pre> <p>When you change the alpha without changing the premultiplied color components, the result doesn't change—when you draw the image, it will look no different, because the colors are still premultiplied by the old alpha.</p> <p>So, you need to unpremultiply the colors—that is, divide each one by the alpha (as previously it was multiplied, so you must now do the inverse)—before you change the alpha. Then, after changing the alpha, premultiply the colors by the new alpha.</p> <p>Of course, this means that when changing the alpha to zero, all the colors will go black (r=g=b=0). So, make sure you keep the original image if the user might want to change it back.</p> <p>It would probably be more effective, and would certainly be easier, to just draw the original image (without any alpha changes made to it) at whatever alpha the user wants. You can do this by <a href="https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html#//apple_ref/c/func/CGContextSetAlpha" rel="nofollow noreferrer">changing your display context's global alpha</a> before you draw the image.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload