views:

236

answers:

1

If I load a bitmap using a loader in Flex, I can use the loaderInfo.bytesTotal to get the size, total bytes used, of a bitmap.

If I create a bitmap in run time, how can I find out the size, the total bytes used, by that bitmap.

Please advice. Thanks

+2  A: 

var bitmapByteSize:int = bitmap.bitmapData.getPixels(bitmap.bitmapData.rect).length;

That might do the trick.

JStriedl
JStriedl, thanks for your reply. I have tried a similar method before.var byteArray:ByteArray = _bitmap.bitmapData.getPixels(new Rectangle(0, 0, _bitmap.width, _bitmap.height));_bitmapTotalBytes = byteArray.length;However, _bitmapTotalBytes is much larger than the original jpg file, although I have already reduce the width and height.Do you know why? Thanks.
michael
The jpeg format is compressed when stored on disk, and must be decompressed for display. So, the length of the ByteArray will be much larger than the file, as it represents the pixel data in uncompressed, displayable format, NOT the original compressed JPEG file size.
JStriedl
Striedl, Thanks.
michael