2

Is there an example of a bitmap color replacement implementation that actually works?

I'm trying to achieve the following:

Before:

After:

Note: I'm not trying to use a color matrix transformation here. I want the ability to select 1 color, then select a threshold, and then select a new color which would effectively shift all the colors in the threshold.

Is this idea possible to execute very accurately? If so can you point me to a proof-of-concept?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Arturino
  • 358
  • 7
  • 19

1 Answers1

2

Just to get the ball rolling on this... I don't know that this is going to be the right solution for you but it's a start.

This answer shows how to use the BitmapData.threshold method to replace colors. You could replace a color with a transparent pixel, then put a background behind your MovieClip and animate between colors.

var inputBitmapData:BitmapData = new BitmapData(200, 200, true, 0xFF0000FF);
inputBitmapData.fillRect(new Rectangle(10, 10, 180, 180), 0xFFFF0000);

var outputBitmapData:BitmapData = new BitmapData(200, 200, true); 
var destPoint:Point = new Point(0, 0); var sourceRect:Rectangle = new Rectangle(0, 0, outputBitmapData.width, outputBitmapData.height); 
var threshold:uint =  0xFFFF0000;  
var color:uint = 0x00000000;     
outputBitmapData.threshold(inputBitmapData, sourceRect, destPoint, "==", threshold, color, 0xFFFFFFFF, true);

var input:Bitmap = new Bitmap(inputBitmapData); addChild(input);
var output:Bitmap = new Bitmap(outputBitmapData); output.x = input.x + input.width + 10; 

addChild(output);

You could also loop through the bitmapdata pixel by pixel to replace one color with another.

for (var j = 0; j < bitmap.height; j++) {
    for (var i = 0; i < bitmap.width; i++) {
        if(bitmapData.getPixel(i,j)==0xFFFF00)  {
            bitmapData.setPixel(i,j, 0xFF0000);
        }
    }
}
Community
  • 1
  • 1
potench
  • 3,802
  • 1
  • 28
  • 39
  • thanks for getting this started. Will this method SHIFT or exactly replace a threshold of colors with the new color? i.e. :: a light blue and dark blue pixel ( grouped together by the threshold setting ) convert to light red and dark red when the user selects RED. – Arturino Jun 21 '12 at 21:09
  • I think this will replace 1 color with 1 color. You could set up a mapping and feed it multiple colors to replace but I'm thinking there's a better way to do this. Sorry, just trying to get you pointed in a direction (hopefully not the wrong direction) – potench Jun 21 '12 at 21:25