0

有没有办法将 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 函数。

4

1 回答 1

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() 命令令人满意地工作,但我不明白为什么它不应该。请让我知道结果如何!

于 2010-01-02T16:19:48.893 回答