Flash 8: Selective Color Transform
I was asked if my ColorMatrix Class can be used to change only a certain range of colors within a bitmap. Well, that’s mathematically not possible, but nevertheless there is a way to make this work with Flash - it just needs a few more steps and some temporary helper bitmaps.
In short it works like this - if you only want to change the orange parts of an image you first isolate those parts by replacing all other colors with 100%transparent pixels, then you apply the ColorMatrix filter to it and finally draw it over the original bitmap.
Here is the part of the code that creates a mask from a given color range - as you see I’m using several consecutive threshold commands for every color channel.
mask.threshold( original, rect, zero, "<", rmin<<16,0,0x00ff0000,true); mask.threshold( mask, rect, zero, "<", gmin<<8,0,0x0000ff00,true); mask.threshold( mask, rect, zero, "<", bmin,0,0x000000ff,true); mask.threshold( mask, rect, zero, ">“, rmax<<16,0,0x00ff0000,true); mask.threshold( mask, rect, zero, ">“, gmax<<8,0,0x0000ff00,true); mask.threshold( mask, rect, zero, ">“, bmax,0,0×000000ff,true); mask.threshold( mask, rect, zero, “==”, 0xff000000,0xffffffff,0xff000000,true);
I have expanded the concept a bit and added a few tools to clean up and adjust the resulting mask. Check out the demo here:




