Michal Gron avatar Michal Gron committed 5b4443f

+) initial commit

Comments (0)

Files changed (1)

src/samplomat/ImageMeasure.as

+package samplomat
+{
+	import flash.events.Event;
+	import flash.events.IEventDispatcher;
+	import flash.filesystem.File;
+	import flash.filesystem.FileMode;
+	import flash.filesystem.FileStream;
+	import flash.geom.Rectangle;
+	
+	// http://stackoverflow.com/questions/672916/how-to-get-image-height-and-width-using-java
+	public class ImageMeasure implements IEventDispatcher
+	{
+		public function ImageMeasure()
+		{
+		}
+		
+		public function jpeg(file : File) : Rectangle
+		{
+			var dimensions : Rectangle;
+			var marker : int;
+			var length : int;
+			var width : Number, height : Number;
+			var stream : FileStream = new FileStream();
+				stream.open(file, FileMode.READ);
+				
+			if(stream.readUnsignedByte() != 0xFF || stream.readUnsignedByte() != 0xD8) {
+				throw new Error("Not a jpeg file.");
+			}
+			
+			while(stream.readUnsignedByte() == 0xFF)
+			{
+				marker = stream.readUnsignedByte();
+				length = stream.readUnsignedByte() | stream.readUnsignedByte();
+				
+				if(marker == 0xC0)
+				{
+					stream.readUnsignedByte();
+					height = stream.readUnsignedByte() << 8 | stream.readUnsignedByte();
+					width = stream.readUnsignedByte() << 8 | stream.readUnsignedByte();
+					dimensions = new Rectangle(0, 0, width, height);
+					break;
+				}
+				
+				stream.position += (length) - 2;
+			}
+			
+			stream.close();
+			
+			return dimensions;
+		}
+		
+		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
+		{
+		}
+		
+		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
+		{
+		}
+		
+		public function dispatchEvent(event:Event):Boolean
+		{
+			return false;
+		}
+		
+		public function hasEventListener(type:String):Boolean
+		{
+			return false;
+		}
+		
+		public function willTrigger(type:String):Boolean
+		{
+			return false;
+		}
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.