Actionscript 3 AS3单色图像

Actionscript 3 AS3单色图像,actionscript-3,flash,air,Actionscript 3,Flash,Air,我想在内存中保留很多图像作为位图数据。图像是单色的,所以我实际上不需要RGB或RGBA值。有没有办法将bitmapData的内部格式设置为单色,或者使用bitmapData以外的其他方式显示图像?没有,bitmapData没有单色格式 不,不能在任何其他格式中显示图像,例如BitmapData(好的,着色器等,但实际上不同) 但是,您可以使用ByteArray保存当前未使用的数据,以便以后使用某些位图数据,并通过将单通道值拆分为3个值来设置像素。否,位图数据没有单色格式 不,不能在任何其他格式中

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

没有,bitmapData没有单色格式

不,不能在任何其他格式中显示图像,例如BitmapData(好的,着色器等,但实际上不同)


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

否,位图数据没有单色格式

不,不能在任何其他格式中显示图像,例如BitmapData(好的,着色器等,但实际上不同)


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

如果最多有4个相同大小的图像,您可以重复使用单个
BitmapData
对象将所有图像存储在不同的通道中,并使用
ColorMatrixFilter
显示您想要的频道

这将比wvxvw建议的将数据存储在字节数组中并使用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];

如果最多有4个相同大小的图像,可以重复使用单个
BitmapData
对象将所有图像存储在不同的通道中,并使用
ColorMatrixFilter
仅显示所需的通道

这将比wvxvw建议的将数据存储在字节数组中并使用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];