English 中文(简体)
从ALAssetRepresentation中获取知识
原标题:Set Maximum Size for CGImageRef from ALAssetRepresentation

目前,我正在使用以下法典,从位于SOS的一处ALAsset获得UIImage。

ALAssetRepresentation *rep = [self.asset defaultRepresentation];
CGImageRef ref = [rep fullResolutionImage];
ALAssetOrientation orientation = [[self.asset valueForProperty:@"ALAssetPropertyOrientation"] intValue];
UIImage *image = [UIImage imageWithCGImage:ref scale:1.0 orientation:(UIImageOrientation)orientation];

This works very well as long as the image is reasonably small (e.g. taken with the device s camera). However if the image is too large (6000px^2 and more), the app will run out of memory during this step:

CGImageRef ref = [rep fullResolutionImage];

我愿在坠毁之前发现这一状况,或(理想)确定返回图像的最大尺寸。

我知道,fullScreenImage将回归一个较小的形象,然而,该图像需要从动物体积图像中找到更高的分辨率。

Furthermore, using the byte size of the asset is unreliable as highly compressed formats such as JPG may well be small in packed size but still consume too much memory if their size in pixels is high (low detail images, highly compressed images).

如果能就如何掌握图像的尺寸和事先发现这种情况作出投入,以便我能够取消装载和显示错误,或如何找到这种大型资产的较小版本,将受到高度赞赏。

最佳回答

最新资料:

在评论中经过了一些讨论。

你们可以用电话获取档案/资产收益。

[asset metadata]

The reference I found is here sarofox.alasset-image-metadata The page also shows how to get individual properties. This should allow you to get the pixel sizes before you open the file/asset.

MY OLD ANSWER:

下面,如果有人认为有帮助的话:

This is only a guess. But could you not use ALAssetRepresentation getBytes:fromOffset:length:error:

利用你预期的一台照相机图像的星号。

从案卷的开始,从Offset开始,进行核对。 档案长度的长短(希望达到的最高点)。

Read the size in the buffer. If it is smaller than the request then you are ok. If it is exactly the same as the range requested then there may be more left in the file (It maybe bigger.)

如果是的话,提出新的getBytes:摘自Offset:length:error:* 的请求,这一次从最后申请的长度和新期限开始。

You can then add the results up and determine if the whole file will be too large.

但从未有过太多的缓冲/档案

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签