« ActionScript 3 Meets Flickr | Main | Flash Lite 1.1 Inline Text »
November 01, 2005
ActionScript 3 Meets EXIF 2.1
If you have a digital camera, you’re no doubt already familiar with the concept of EXIF data. For those of you that don’t know, when you take a picture with most modern digital cameras, extra information about the configuration of the camera when that picture was taken, is stored in the image file itself. When the picture was taken, shutter speed, f-stop and even GPS information in some cameras are all stored values. Getting at this data programmatically has historically been for the likes of programming languages with fine-grained, low-level control (read: not ActionScript).
Inspired by Darron Schall’s VNC client, it occurred to me that ActionScript 3 and Flash Player 8.5 now have the abilities to go much deeper, much more easily than previously possible. With this in mind, I set to exploring the URLLoader and ByteArray classes and was really impressed. Binary access to data streams, most significant byte order, convenience methods for various read operations and more were all there! This meant that I could now load an image, and then have access to the bits that make up that image. My interest wasn’t so much in the bits that allow for amazing visual effects such as those seen from Andre Michelle and his lightning particles, but rather in the reading of EXIF data.
I had undertaken Flash/EXIF prototypes before for customers interested in Flex, but I leveraged Doug Hughes' (a.k.a. Alagad) EXIF web service (written in C#). I would get a URL for the target image from the user, call the EXIF web service to process the image located at that endpoint, and then display the data in my Flex application. That’s works, but it’s a lot of network traffic, and if I wanted to account for file upload (prior to Flash Player 8), then I had to get into the various Flash/JavaScript hacks and all that they entail.
Wouldn’t it be grand if I could simply read the bits from the image myself – especially since I’m likely to be loading and displaying the image in the UI anyways?
The first challenge was in nailing down the EXIF data structures, which I’m still not sure I completely understand. Pooling the work of various resources, and from libraries coded in everything from PHP to C, I was able to create a quick and dirty port of Thierry Bousch’s EXIF information decoder. The original is written in Python, and I’m proud to say that it now runs quite smoothly, and amazing fast, in Flash Player 8.5 thanks to ActionScript 3 (sample output).
Since Bousch’s original EXIF information decoder simply dumps the data to the console, that’s all my ActionScript 3 version does as well. You can run the code in Flex Builder 2, as an ActionScript project, in debug mode and see all the camera/image details that are fit for viewing. Next up is the obvious port to a more complete object-oriented library, and eventual sharing as open source, but I’ll first need to explore and better understand the various packaging, namespaces and custom errors of ActionScript 3. In the meantime, you’re welcome to peruse my initial (and very sloppy) source.
Posted by khoyt at November 1, 2005 01:30 PM
Comments
Very cool. Bookmarking this idea! :)
Posted by: Chris Charlton at November 1, 2005 03:15 PM
hi i want to ask some question about flash lite
I am currently try to develop a flash content which the content will be download to a mobile phone from the server, i feel curious in some of the operating in the medium of connecting. here it goes
If my flash content is embed in a webpage and can be view in a mobile phone, how are we going to dynamically displaying the updated content in the page. ?
how to code in flash lite?
If we are using .NET , how the flash lite going to related itself to the .NET and retrive the data from the database?
Christine
Posted by: Christine at November 17, 2005 02:36 AM
Man o Man!
You guys are simply superb. I mean, I just thought about - "why not read EXIF with AS", and try out googling once, and here you are - already made it working!
Awesome work!
Posted by: Arul Prasad at February 27, 2006 11:31 PM
I've tried implementing this class. It works great with photos that come straight out of the camera untampered. Thanks.
However, this class awkwardly doesn't work when you resize and save out of Photoshop cs2, even though the photo still contains the same exif data (exif is NOT stripped). Thoughts anyone?
Posted by: Richard at August 17, 2006 04:15 PM