有没有办法将colorTransform应用于圆形而不是矩形中的BitmapData?
不是像下面的代码中那样通过减少alpha通道来删除图像的矩形部分,而是想在圆圈中进行。
_bitmap.colorTransform(new Rectangle(mouseX-d/2, mouseY-d/2, d, d),
new ColorTransform(1, 1, 1, .5, 0, 0, 0, 1));
我确实有一些循环像素的代码,提取alpha值并使用setPixel,但它的接缝明显慢于colorTransform函数。
答案 0 :(得分:1)
尝试使用绘图API(flash.display.Graphics)创建一个圆,然后使用BlendMode.ERASE将其绘制到位图数据上。如果我理解正确的话,这可能会解决您的问题。
var circle : Shape = new Shape;
circle.graphics.beginFill(0xffcc00, 1);
circle.graphics.drawEllipse(-50, -50, 100, 100);
// Create a transformation matrix for the draw() operation, with
// a translation matching the mouse position.
var mtx : Matrix = new Matrix();
mtx.translate(mouseX, mouseY);
// Draw circle at mouse position with the ERASE blend mode, to
// set affected pixels to alpha=0.
myBitmap.draw(circle, mtx, null, BlendMode.ERASE);
我不是100%确定ERASE混合模式使用draw()命令可以令人满意地工作,但我不明白为什么它不应该。请让我知道它是如何工作的!