Hello!
I use a fileReference.browse() to select an image file from the harddrive.
How can I check the Width and Height of the selected image file please?
Thank you!
Hello!
I use a fileReference.browse() to select an image file from the harddrive.
How can I check the Width and Height of the selected image file please?
Thank you!
From the context of Flex, I'm pretty sure that onc you get the results back from a browserr, it is only a byteArray. In theory if you use that byteArray as the source for an image tag you'll be able to get the height and width that way, once you add that image to a container.
Otherwise, I do not believe there is an easy way to get such metadata info from local files using Flex.
Load the fileReference.data into a Loader using loadBytes(). Then you'll have: sourceBMP:Bitmap = loader.content as Bitmap;
Here is a sample code:
MXML part:
<fx:Declarations>
<net:FileReference id="fileReference"
select="fileReference_select(event);"
complete="fileReference_complete(event);" />
</fx:Declarations>
<s:Button id="uplaodImageBtn"
label="Upload Image"
click="uplaodImageBtn_clickHandler()"/>
AS3 part:
private function uplaodImageBtn_clickHandler() : void {
var arr:Array = [];
arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
fileReference.browse(arr);
}
private function fileReference_select(evt:Event):void {
fileReference.load();
}
private function fileReference_complete(event:Event):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
loader.loadBytes(fileReference.data);
}
public function loader_complete (event:Event) : void {
var sourceBMP:Bitmap = event.currentTarget.loader.content as Bitmap;
Alert.show(sourceBMP.width + ', ' +sourceBMP.height);
}