如何设置一个特定的颜色是透明的? [英] How do I set a certain color to be transparent?

查看:141
本文介绍了如何设置一个特定的颜色是透明的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 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?

推荐答案

您可以使用<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#threshold%28%29"相对=nofollow> BitmapData.threshold 方法。这code创建了在蓝色背景上的红色方块的BitmapData,然后使用阈值法,使红色像素透明。

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

这篇关于如何设置一个特定的颜色是透明的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆