1

嗨,我想用另一种颜色替换位图中的特定颜色。如果阈值颜色值没有 alpha,则 BitmapData.threshold() 函数可以正常工作。

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)); 
}

以上方法有效,除非您尝试更改具有 alpha 的颜色,否则它不会。即将阈值变量的值从0xFF004d5e更改为0x37004d5e,即更改具有 alpha 通道的颜色,然后它就不起作用了,但这就是我想要的!任何人都有任何想法,当阈值颜色具有 alpha 时,如何使 BitmapData.threshold() 函数工作?

4

0 回答 0