2010-01-02 82 views
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)); 

我确实有一些代码,通过像素循环,提取α值,并使用setPixel但接缝比的ColorTransform功能显著慢。

+0

by setPixel你正在使用BitmapData的权利? – chakrit 2010-01-02 16:16:14

+0

是的,在使用alpha通道时也需要使用setPixel32。 – 2010-01-02 17:39:26

回答

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混合模式与平局()命令的工作令人满意,但我不明白为什么它不应该。请让我知道它是如何运作的!

+0

工程魅力!我做的唯一更改是将圆的填充设置为alpha .5或更低,以获得与我使用的colorTransform相同的效果。这是为了更慢地擦除图像。非常感谢。 – 2010-01-02 17:12:52

+0

另一种方法是对draw方法_bitmap.draw(circle,mtx,new ColorTransform(1,1,1,.5),0,0,0,1)BlendMode使用3rd,ColorTransform参数。 ERASE) – 2010-01-02 17:37:59

+0

我很高兴!关于使用ColorTransform只是为了减少alpha,我的直觉告诉我,它不可能执行以及在圆圈填充上只有一个<1的alpha。简单地说,因为ColorTransform将在您每次绘制时应用(并在示例代码中实例化),这意味着一次额外的操作。 – richardolsson 2010-01-02 20:11:25