views:

420

answers:

2

I have two BitmapData objects with alpha channels. I'd like to combine them into a single one by using max(channel_image_one, channel_image_two) for each channel, including the alpha. Is there an easy way to achieve this result?

+1  A: 

I don't think there's straight forward bitmapdata method to merge the Alpha chanel that way. RGB could maybe do with the help of draw() applying a blend mode, but I don't think it would work if you need a strict max per chanel).

Besides, you can create a shader thanks to PixelBender to perform this task. It's the perfect tool for that kind of manipulations.

Slower in performance but quicker to setup if your not used to PB you could just iterate/compare/write the pixels one by one with BitmapData.getPixel32()/setPixel32(). In case you go for that, think about using BitmapData.lock()/unlock() to boost performance.

Theo.T
A: 

If you want max(image_one,image_two) that should be equivalent to the LIGHTEN blend mode.

Here is a snippet from Foundation ActionScript 3.0 Image Effects :

public function lighten(topPixel:uint, bottomPixel:uint):uint{
   return Math.max(topPixel,bottomPixel);
}

You can get the needed as files from the chapter 2 folder of the source zip.

Use Theo's advice with

  • lock()
  • for loops
  • unlock()

for speed with BitmapData or use PixelBender. Apparently according to Adobe, over 90% of the Flash Player user already use version 10.

George Profenza