AS3单色图像

时间:2012-03-25 10:49:23

标签: actionscript-3 flash air

我想在内存中保留很多图像作为bitmapData。图像是单色的,所以我实际上不需要RGB或RGBA值。有没有办法将bitmapData的内部格式设置为单色或其他方式来显示除使用BitmapData之外的图像?

2 个答案:

答案 0 :(得分:2)

不,BitmapData没有单色格式。

不,你不能在其他任何地方显示图像BitmapData(好的,着色器等等,但它真的不一样)。

但是,您可以使用ByteArray保存当前未使用的数据,以便以后使用某些BitmapData和setPixel通过将单个通道值拆分为3个值来设置像素。

答案 1 :(得分:1)

如果您最多有4张相同尺寸的图片,则可以重复使用一个BitmapData对象将所有图片存储在不同的频道中,然后使用ColorMatrixFilter只显示您的频道想。

这比wvxvw建议将数据存储在ByteArray中并使用setPixel更快(并且可能更少的代码)。

// store data in the red channel
bitmap.bitmapData.copyChannel( im1.bitmapData, im1.bitmapData.rect, new Point(), BitmapDataChannel.RED, BitmapDataChannel.RED );
// store data in the green channel
bitmap.bitmapData.copyChannel( im2.bitmapData, im2.bitmapData.rect, new Point(), BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);

// e.g. filter the bitmap to just show the green channel
// (1's in first col for red, 3rd col for blue, 4th for alpha
var greenChannelFilter:ColorMatrixFilter = new ColorMatrixFilter( 
            [ 0,1,0,0,0,
              0,1,0,0,0,
              0,1,0,0,0,
              0,0,0,0,255 ]);
bitmap.filters = [greenChannelFilter];
相关问题