Actionscript 3 - 在位图上绘制具有透明度的draw()

发布于 2024-12-14 05:26:43 字数 258 浏览 4 评论 0原文

我想将透明度应用于不透明徽标,然后将其添加到图像中。 因此,我更改徽标的 alpha,然后在图像上绘制()徽标。 但它不起作用,透明度没有按预期应用。

注意:我稍后会将生成的 bitmapData 保存到文件中,因此 addChild() 不足以解决此问题。

var image:Bitmap;
var logo:Bitmap;
//...
logo.alpha = 0.3;
image.bitmapData.draw(logo);

I want to apply transparency to a non-transparent logo then add it to an image.
So I change the alpha of the logo, then I draw() the logo on the image.
But it doesn't work, the transparency isn't applied as expected.

Note: I will later save the resulting bitmapData to a file, so an addChild() won't be enough to solve this.

var image:Bitmap;
var logo:Bitmap;
//...
logo.alpha = 0.3;
image.bitmapData.draw(logo);

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

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

发布评论

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

评论(1

十六岁半 2024-12-21 05:26:43

试试这个:

var adjustAlpha:ColorTransform = new ColorTransform();
adjustAlpha.alphaMultiplier = 0.3
var logoArea:Rectangle = new Rectangle(0, 0, logo.width, logo.height);
logo.bitmapData.colorTransform(logoArea, adjustAlpha);
image.bitmapData.draw(logo);

当您修改位图的 alpha 值时,您并没有修改它的实际位图数据,因此当您绘制它时,您仍然复制在 bitmapData 中找到的未修改的数据。

上面的代码使用 colorTransform 属性来调整 bitmapData 中的每个像素,您可以通过更改矩形的大小来定位特定区域。

(您还需要导入 ColorTransform 类)。

try this:

var adjustAlpha:ColorTransform = new ColorTransform();
adjustAlpha.alphaMultiplier = 0.3
var logoArea:Rectangle = new Rectangle(0, 0, logo.width, logo.height);
logo.bitmapData.colorTransform(logoArea, adjustAlpha);
image.bitmapData.draw(logo);

When you modify the alpha value of a bitmap you aren't modifying it's actual bitmapdata, so that when you draw it you are still copying the unmodified data found in bitmapData.

The code above uses the colorTransform property to adjust every pixel in bitmapData, you can target specific areas by changing the size of the rectangle.

(You will need to import the ColorTransform class also).

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