如何将某种颜色设置为透明?

发布于 2024-10-24 02:40:18 字数 122 浏览 6 评论 0原文

我使用 copyPixels 将较大位图的一部分复制到较小的位图以用于单个影片剪辑。然而,周围仍然存在一些额外的空白空间和位图边缘周围的角点。如何将位图中的白色设置为透明,这样我就不会看到这些难看的边缘?

I'm using copyPixels to copy a parts of a larger Bitmap to smaller Bitmaps to use for individual MovieClips. However, around there is still some extra space white space and corners around the Bitmaps' edges left over. How do I set the color white in the Bitmap to be transparent so I won't see these unsightly edges?

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

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

发布评论

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

评论(2

绿光 2024-10-31 02:40:18

您可以使用 BitmapData .threshold 方法。此代码创建一个蓝色背景上有红色方块的 BitmapData,然后使用阈值方法使红色像素透明。

var inputBitmapData:BitmapData = new BitmapData(200, 200, true, 0xFF0000FF);
inputBitmapData.fillRect(new Rectangle(10, 10, 180, 180), 0xFFFF0000);

var outputBitmapData:BitmapData = new BitmapData(200, 200, true);
var destPoint:Point = new Point(0, 0);
var sourceRect:Rectangle = new Rectangle(0, 0, outputBitmapData.width, outputBitmapData.height);
var threshold:uint =  0xFFFF0000; 
var color:uint = 0x00000000;
outputBitmapData.threshold(inputBitmapData, sourceRect, destPoint, "==", threshold, color, 0xFFFFFFFF, true);

var input:Bitmap = new Bitmap(inputBitmapData);
addChild(input);

var output:Bitmap = new Bitmap(outputBitmapData);
output.x = input.x + input.width + 10;
addChild(output);

You can use the BitmapData.threshold method. This code creates a BitmapData with a red square on a blue background, then uses the threshold method to make the red pixels transparent.

var inputBitmapData:BitmapData = new BitmapData(200, 200, true, 0xFF0000FF);
inputBitmapData.fillRect(new Rectangle(10, 10, 180, 180), 0xFFFF0000);

var outputBitmapData:BitmapData = new BitmapData(200, 200, true);
var destPoint:Point = new Point(0, 0);
var sourceRect:Rectangle = new Rectangle(0, 0, outputBitmapData.width, outputBitmapData.height);
var threshold:uint =  0xFFFF0000; 
var color:uint = 0x00000000;
outputBitmapData.threshold(inputBitmapData, sourceRect, destPoint, "==", threshold, color, 0xFFFFFFFF, true);

var input:Bitmap = new Bitmap(inputBitmapData);
addChild(input);

var output:Bitmap = new Bitmap(outputBitmapData);
output.x = input.x + input.width + 10;
addChild(output);
沉溺在你眼里的海 2024-10-31 02:40:18

您可以使用 BitmapData.colorTransform()draw() 而不是 copyPixels() 来调整颜色

you can use BitmapData.colorTransform() or draw() instead of copyPixels() to adjust color there

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