Get dimension of locally loaded large image
I'm trying to read the width and height of a locally loaded image. This seems to work for images that do not exceed the dimensions limited by the Flash Player 10 (http://kb2.adobe.com/cps/496/cpsid_49662.html), but as soon as the images are bigger, the width and height remain 0. The strange thing is that now and then, I can read the dimension of these bigger images, but most of the times not. I understand that this might be because of the player limitation, but then I would at least expect the error to be consistent.
I want to check this since there is no use in loading such a big image as it will not be displayed anyway, but it would be good to provide a detailed error message to the user.
Any ideas on this?
Here's the code that I use to load the image locally and read the dimension:
private function chooseImageButton_clickHandler(event:Event):void {
var allowedTypes:String = "*.jpg;*.png";
m_uploadFileReference = new FileReference();
m_uploadFileReference.addEventListener(Event.SELECT, uploadFileReference_selectHandler);
m_uploadFileReference.addEventListener(Event.COMPLETE, uploadFileReference_completeHandler);
m_uploadFileReference.browse(开发者_JAVA百科[new FileFilter("Image Files (" + allowedTypes + ")", allowedTypes)]);
}
private function uploadFileReference_selectHandler(event:Event):void {
m_uploadFileReference.load();
}
private function uploadFileReference_completeHandler(event:Event):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.loadBytes(m_uploadFileReference.data);
}
private function onImageLoaded(e:Event):void {
trace(e.target.content.width);
}
You can skip loading the entire image and just reading the headers with this class.
var je : JPGSizeExtractor = new JPGSizeExtractor( );
je.addEventListener( JPGSizeExtractor.PARSE_COMPLETE, sizeHandler );
je.extractSize( your_jpg_file.jpg );
function sizeHandler( e : Event ) : void {
trace( "Dimensions: " + je.width + " x " + je.height );
}
Should be both faster and more reliable.
I would at least expect the error to be consistent.
Well, at least Adobe are pretty clear on that point: "...if you choose to develop beyond these boundaries we cannot guarantee consistent behavior."
Could you perhaps upload your image to a php pre-processor? (Here's one from Google)
精彩评论