May 17 2009

Extracting image binary info without loading the entire file

Category: ClassesHadi Tavakoli @ 10:37 pm

Well, today I surely teared myself apart! I spent about 10 hours to get myself femiliar with how the three most popular image formats, jpg, png and gif work and how we can use the flash AS3 ByteArray class to extract this information!

I must confess that I still am very unclear about a lot of different things in byteArray class but the least I managed was to find and combine some classes and finally managed to output the kind of information I needed.

Before anything I must thank to Antti, who wrote the beautiful class of how we can read and use binary data of jpg file. you may read his artical here.

The problem with Antti class was that his class supported jpeg format only and didn't extract all the other information I needed and actually was too bugy for my needs!

So, I had to do some more searches here and there and I found this other artical here which did made me happy by how it extracted image info and it supported all the three formats. but the problem with this latter class was that it actually extracted all the data just after it loaded the whole file entirely! which in practice makes it useless, at least for my purpose.

So, I have the two classes, one tells me how to search for the information I need the other one tells me how to kill the loading process as soon as I found out the information I was looking for!

ok, good, finally what I did was to combine the two classes together and build a new class which you can download here:
http://emstris.com/sample/AS3/byteArray/ImageInfoExtractor.as
(simply put it in your class files in this location: com\myflashlab\classes\tools\imageEncoders)

and using this new class I put together, you can find out a lot of information about images before they are downloaded entirely :) actually this information gets extracted in just a second! maybe less than a second.

you will be able to use the above class like this:


		  
		  
		  
		  
		  
		  
		

looks nice and clean, right? yeah, this will be absolutly useful in big and complex projects.
I have also a sample online, check below and see how the class has extracted the information out of the big image, about 800 kb, in just a second! and kills the connection right after that.

 

I hope you enjoy the class. just one thing, I would really love to be able to find out the header binary information of a swf file also. if anyone managed to update this class so that it also supports .swf input, I'd be more than happy to have it also :)

Thanks,
Hadi

Tags: , , , , , , , , , , , , ,