2012-12-15 19 views
1

我希望能夠更改圖像(特別是位圖),以便在ActionScript 3中用白色替換所有深灰色和黑色像素,但在圖像中保留所有其他顏色。我熟悉ColorMatrixFilter和bitmapdata.threshold,但我不知道如何使用它們來定位要移除的顏色或在特定顏色範圍內進行檢查。有沒有什麼(有效的)方法可以做到這一點?AS3 - 如何從位圖中刪除所有黑色和灰色,但保留顏色?

感謝您提供任何幫助。

回答

0

AS3 API提供了有關如何使用treshhold值的相當不錯的文檔。你可以找到它here。他們的例子實際上檢查了一定範圍的顏色。我修改了他們的示例以解決您的問題。我沒有測試過它,所以它可能需要一些調整。

var bmd2:BitmapData = new BitmapData(200, 200, true, 0xFFCCCCCC); 
var pt:Point = new Point(0, 0); 
var rect:Rectangle = new Rectangle(0, 0, 200, 200); 
var threshold:uint = 0x00A9A9A9; //Dark Grey 
var color:uint = 0x00000000; //Replacement color (white) 
var maskColor:uint = 0xFFFFFFFF; //What channels to affect (this is the default). 
bmd2.threshold(bmd1, rect, pt, ">", threshold, color, maskColor, true); 

另一種選擇是使用雙重for循環對所有像素進行迭代,並且採用基於像素的值有一定作用。

for(var y:int = 0; y < height; y++){ 
    for(var x:int = 0; x < width; x++){ 
    var currentPixel:uint = image.getPixel(x, y); 
    if(currentPixel != color){ 
     image.setPixel(destPoint.x + j, destPoint.y + i, currentPixel); 
    }   
    } 
} 
+0

我沒意識到你可以用閾值做範圍。漂亮!感謝您的迴應,我會給它一個旋轉。 :) – lunaria

相關問題