Hi I would like to replace a specific color in a bitmap with another one. The BitmapData.threshold() function works fine if the threshold color value has no alpha.
var threshold:uint = 0xFF004d5e; // this works, however if I use this 0x37004d5e, ie the same color with an alpha then it doesnt
var baseColour:uint = 0x3700c5e0;
var targetColour:uint = 0x37F38900;
var inputBitmapData:BitmapData = new BitmapData(200, 200, true, baseColour);
inputBitmapData.fillRect(new Rectangle(10, 10, 180, 180), threshold);
var input:Bitmap = new Bitmap(inputBitmapData);
addChild(input);
replaceColour(inputBitmapData,threshold,targetColour);
function replaceColour(bitmapData:BitmapData,colorToReplace:uint, newColor:uint):void
{
trace(" replaced:"+ bitmapData.threshold(bitmapData, new Rectangle(0, 0, bitmapData.width, bitmapData.height), new Point(), "==", colorToReplace, newColor, 0xFFFFFFFF));
}
The above works, unless you are trying to change a color that has an alpha, then it doesnt. ie change the threshold variable's value from 0xFF004d5e to 0x37004d5e, ie to change a color which has an alpha channel, and then it wont work, but that is what I want! Anyone has any ideas, how to make the BitmapData.threshold() function work when the threshold color has an alpha??