获取本地装载大图像的尺寸图像、尺寸

2023-09-09 21:27:46 作者:伱不懂愛゛卻懂傷害

我想读本地加载图像的宽度和高度。这似乎工作图像,不超过的限制与Flash Player 10( HTTP尺寸: //kb2.adobe.com/cps/496/cpsid_49662.html ),但只要图像越大,宽度和高度仍然是0。奇怪的是,现在,然后,我的可阅读这些大图像的尺寸,但大多数时候并非如此。据我所知,这可能是由于播放器的限制,但我至少希望错误是一致的。

我要核对一下,因为在加载这么大的图像,因为它不会显示反正没什么用,但它是很好的提供了详细的错误信息给用户。

对此有何想法?

下面是我用本地加载图像并读取尺寸的code:

 私有函数chooseImageButton_clickHandler(事件:事件):无效{
  VAR allowedTypes:字符串=* .JPG; * PNG。
  m_uploadFileReference =新的FileReference();
  m_uploadFileReference.addEventListener(Event.SELECT,uploadFileReference_selectHandler);
  m_uploadFileReference.addEventListener(引发Event.COMPLETE,uploadFileReference_completeHandler);
  m_uploadFileReference.browse([新的FileFilter(图像文件(+ allowedTypes +),allowedTypes)]);
}

私有函数uploadFileReference_selectHandler(事件:事件):无效{
  m_uploadFileReference.load();
}

私有函数uploadFileReference_completeHandler(事件:事件):无效{
  VAR装载机:装载机=新的Loader();
  loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,onImageLoaded);
  loader.loadBytes(m_uploadFileReference.data);
}

私有函数onImageLoaded(五:事件):无效{
  跟踪(e.target.content.width);
}
 

解决方案

您可以跳过加载整个形象,只是阅读本类。

  VAR JE:JPGSizeExtractor =新JPGSizeExtractor();
je.addEventListener(JPGSizeExtractor.PARSE_COMPLETE,sizeHandler);
je.extractSize(your_jpg_file.jpg);

功能sizeHandler(五:事件):无效{
跟踪(尺寸+ je.width +X+ je.height);
}
 
photoshop载入图案的问题

应速度更快和更可靠。

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([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.