问题描述
限时送ChatGPT账号..我正在尝试读取本地加载图像的宽度和高度.这似乎适用于不超过 Flash Player 10 (http://kb2.adobe/cps/496/cpsid_49662.html),但是一旦图像变大,宽度和高度就保持为 0.奇怪的是,我不时可以读取这些较大图像的尺寸,但大多数情况下不能.我知道这可能是因为玩家限制,但我至少希望错误是一致的.
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/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.
对此有什么想法吗?
这是我用来在本地加载图像并读取尺寸的代码:
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([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);
}
推荐答案
您可以跳过加载整个图像而只需阅读标题 class.
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 );
}
应该更快更可靠.
这篇关于获取本地加载的大图的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论