【问题标题】:circular colorTransform圆形颜色变换
【发布时间】:2010-12-31 19:27:08
【问题描述】:

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

【问题讨论】:

  • by setPixel 你用的是BitmapData对吗?
  • 是的,您还需要在使用 Alpha 通道时使用 setPixel32。

标签: actionscript-3 bitmap alpha bitmapdata colortransform


【解决方案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() 命令令人满意地配合使用,但我不明白为什么它不应该。请告诉我结果如何!

【讨论】:

  • 很有魅力!我所做的唯一更改是将圆的填充设置为 alpha 0.5 或更小,以实现与我使用的 colorTransform 相同的效果。那就是更慢地擦除图像。非常感谢。
  • 另一种方法是使用绘图方法的第三个 ColorTransform 参数 _bitmap.draw(circle, mtx, new ColorTransform(1, 1, 1, .5), 0, 0, 0, 1), BlendMode.ERASE)
  • 我很高兴!关于仅使用 ColorTransform 来降低 alpha,我的直觉告诉我,它不可能像在圆形填充上简单地具有
  • 它的性能可能不那么好,但它看起来稍微好一些,因为你不会让圆形边缘出现太多。再次感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-24
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-28
  • 1970-01-01
相关资源
最近更新 更多