Mat
Mat

Reputation: 4501

AS3 monochromatic images

I'd like to keep a lot of images as bitmapData in memory. The images are monochromatic, so I actually don't need RGB or RGBA values. Is there any way to set the internal format of a bitmapData to monochromatic or another way to display images other than using BitmapData?

Upvotes: 0

Views: 186

Answers (2)

Peter Hall
Peter Hall

Reputation: 58735

If you have up to 4 images the same size, you could re-use a single BitmapData object to store all of them in different channels, and use a ColorMatrixFilter to show just the channel you want.

This would be faster (and probably less code) than wvxvw's suggestion of storing the data in a ByteArray and using 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];

Upvotes: 1

user797257
user797257

Reputation:

No, there's not monochromatic format for BitmapData.

No, you can't display images in anything other them BitmapData (ok, shaders and such, but it's really not the same).

However, you could use ByteArray to save the data not used currently to later use some BitmapData and setPixel to set pixels by splitting the single channel value into 3 values.

Upvotes: 2

Related Questions