ActionScript 3 来自JPG的XMP元数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 来自JPG的XMP元数据相关的知识,希望对你有一定的参考价值。

private function init(event:Event):void
{
	var ldr:Loader = new Loader();
	ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
	var s:String = "link/to/asset.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);

	//trace(xmpXML);
	var meta:XMPMeta = new XMPMeta(xmpXML);
}
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);
	/* 
	http://www.adobe.com/devnet/xmp.html
	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(""+PACKET);
	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;
	for(q=1;q<j;q++){
		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);
}

以上是关于ActionScript 3 来自JPG的XMP元数据的主要内容,如果未能解决你的问题,请参考以下文章

图像元数据信息EXIF和XMP

ActionScript 3 从Flash CS3保存JPG图像

ActionScript 3 SWF元数据标签

ActionScript 3 AS3 SWF元数据

ActionScript 3 AS3 FLVPlayback组件视频元数据

在 ImageMagick 中应用 XMP 照片处理