Getting image dimensions from raw data

What do you do when you need to convert ByteArray with GIF, PNG or JPG to BitmapData for immediate use with beginBitmapFill(), for example? Since Loader´s loadBytes() method makes you wait for COMPLETE event, the only solution I can think of is to create empty BitmapData first to be used immediately and then update it using draw(), when real BitmapData is ready. Nice trick, you might think, but the question is, what should empty BitmapData dimensions be?

ImageUtil class answers this question for all image formats supported by Loader (listed above). To that end, it combines efforts of several people, including myself. Back in 2007, Antti Kupila wrote his JPGSizeExtractor class; then in 2009 Geoffrey McRae cut some corners to simplify it a bit. Finally, in 2010 Christophe Herreman wrote his PNGSizeExtractor class, and now I completed the list with similar procedure for GIFs.

You can see combined result in action here (mxml source here).

0 Responses to “Getting image dimensions from raw data”



  1. Leave a Comment

Ask a Question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Old stuff

July 2010
M T W T F S S
« Jun   Sep »
 1234
567891011
12131415161718
19202122232425
262728293031  

Oh, btw…


%d bloggers like this: