1 Reply Latest reply on Aug 8, 2012 3:22 AM by Mac_06

    Read Image XMP Metadata

    Mac_06 Level 2

      Hi All,

      Hope I'm not spamming  this thread to your mailbox as I felt this question asked in unrelated  forum.


      Question: Can we read image meta data from Flex ?


      I tried it with xmp core library and passed a jpeg file to xmpMeta object :

      private function getImageMetadata(jpeg:File):void
                                    var meta:XMPMeta = new XMPMeta(jpeg);
                                    var packet:XML = meta.serializeToXML();
                                    var photoshop:Namespace = XMPConst.photoshop;
                                    var value:String = meta.photoshop::AuthorsPosition;
                                      trace(value); // returns null, not sure why


      Can any one help me to get the image metadata.


      Thanks in advance


        • 1. Re: Read Image XMP Metadata
          Mac_06 Level 2

          I've got some content related to my issue from net but still it won't solve my problem


          private function init():void {


                                                  var ldr:Loader = new Loader();

                                                  ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);

            var s:String = "my/jpgPath/myjpgName.jpg";

                                                  ldr.load(new URLRequest(s));





                                        private function imgLoaded(e:Event):void{


                                                  var info:LoaderInfo = e.target as LoaderInfo;

                                                  var xmpXML:XML = getXMP(info.bytes);



                                                  var meta:XMPMeta = new XMPMeta(xmpXML);

            //var packet:XML = meta.serializeToXML();

                                                  var photoshop:Namespace = XMPConst.photoshop





                                        private function trim(s:String):String{

            return s.replace( /^([\s|\t|\n]+)?(.*)([\s|\t|\n]+)?$/gm, "$2" );


                                        private function getXMP(ba:ByteArray):XML{

                                                  var LP:ByteArray = new ByteArray();

                                                  var PACKET:ByteArray = new ByteArray();

                                                  var l:int;


                                                  ba.readBytes(LP, 2, 2);



                                                  read part 3: Storage in Files.


                                                  that will explain the -2 -29 and other things you see here.


                                                  l = LP.readInt() - 2 -29;

                                                  ba.readBytes(PACKET, 33, l);

                                                  var p:String = trim(encode(PACKET) as String);

            var i:int = p.search('<x:xmpmeta xmlns:x="adobe:ns:meta/"');

            /* Delete all in front of the XMP XML */

                                                  p = p.substr(i);


                                                  For some reason this left some rubbish in front, so I'll hardcode it out for now


                                                  TODO clean up



                                                  var ar:Array = p.split('<');

                                                  var s:String = "";

                                                  var q:int;

                                                  var j:int = ar.length;


                                                            s += '<'+ar[q];


                                                  i = s.search('</x:xmpmeta>');

                                                  i += ('</x:xmpmeta>').length;

                                                  s = s.slice(0,i);

            /* Delete all behind the XMP XML */

                                                  return XML(s);



                                        private static function encode(ba:ByteArray):String {

            var origPos:uint = ba.position;

            var result:Array = new Array();


             for (ba.position = 0; ba.position < ba.length - 1; )



            if (ba.position != ba.length)

             result.push(ba.readByte() << 8);


            ba.position = origPos;

                                                            return String.fromCharCode.apply(null, result);




          It seems there is a bug in XMPMeta class where it always throws an exception "The XMPMeta object cannot have qualifiers", Even created with default (no param).


          Does anyone have any clue on this? please help