圆形颜色变换

发布于 2024-08-16 09:47:55 字数 327 浏览 3 评论 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 函数明显慢得多。

Is there a way to apply a colorTransform to a BitmapData in a circle rather than in a rectangle?

Instead of erasing rectangular parts of an image by reducing the alpha channel as in the code below, I'd like to do it in circles.

 _bitmap.colorTransform(new Rectangle(mouseX-d/2, mouseY-d/2, d, d),
 new ColorTransform(1, 1, 1, .5, 0, 0, 0, 1));

I do have some code which loops through the pixels, extracts the alpha value and uses setPixel but it seams significantly slower than the colorTransform function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2024-08-23 09:47:55

尝试使用绘图 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() 命令配合使用,但我不明白为什么它不能。请让我知道结果如何!

Try creating a circle using the drawing API (flash.display.Graphics) and then drawing that onto the bitmap data with BlendMode.ERASE. That might solve your problem, if I understand it correctly.

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);

I'm not 100% sure that the ERASE blend mode works satisfyingly with the draw() command, but I can't see why it shouldn't. Please let me know how it works out!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文