Exif, or Exchangeable image file format is a specification for image formats used by digital cameras and scanners. It's also used to store metadata such as camera model, type, author etc. Learn to display Exif metadata in your application by following this Quick Tip.
Step 1: Brief Overview
We'll use an excellent library to load and parse the Exif information of a JPG file; the data will be then displayed in a Dynamic TextField. You can download the library from the developer's site.
Step 2: Set Up Your Flash File
Launch Flash and create a new Flash Document, set the stage size to 320x480px and the frame rate to 24fps.
Step 3: Interface
This is the interface we'll be using; nothing fancy, just a TextField in Stage called infoTF. The image will be dynamically loaded using ActionScript.
Step 4: ActionScript
Create a new ActionScript Class (Cmd+N), save the file as Main.as and write the following lines. Please read the comments in the code to fully understand the class behavior.
package { import flash.display.Sprite; import jp.shichiseki.exif.*; import flash.events.Event; import flash.net.URLRequest; import flash.display.Loader; public class Main extends Sprite { /* An instance of the Exif Loader */ private var loader:ExifLoader = new ExifLoader(); public function Main():void { /* Loads the image and adds a listener to run a function when complete */ loader.addEventListener(Event.COMPLETE, onComplete); loader.load(new URLRequest('img.jpg')); } private function onComplete(e:Event):void { /* Add the image to stage */ loader.scaleX = 0.08;//Scale original image as it is 4000+px wide loader.scaleY = 0.08; loader.x = 195; loader.y = 130; addChild(loader); /* Check the available exif data and display it */ if (loader.exif.ifds.primary) { displayIFD(loader.exif.ifds.primary); } if (loader.exif.ifds.exif) { displayIFD(loader.exif.ifds.exif); } if (loader.exif.ifds.gps) { displayIFD(loader.exif.ifds.gps); } if (loader.exif.ifds.interoperability) { displayIFD(loader.exif.ifds.interoperability); } if (loader.exif.ifds.thumbnail) { displayIFD(loader.exif.ifds.thumbnail); } } private function displayIFD(ifd:IFD):void { /* Adds the read data to the textfield in stage */ for (var entry:String in ifd) { infoTF.appendText(entry + ": " + ifd[entry] + '\n'); } } } }
Step 5: Document Class
Remember to add the class name to the Class field in the Publish section of the Properties panel.
Conclusion
Use this library to access the metadata in your jpg file. Remember that some image editors remove the data when compressing, in which case an error will be thrown by the player.
I hope you liked this Quick Tip, thank you for reading!
Comments