【发布时间】:2012-01-12 18:27:52
【问题描述】:
我目前正在使用以下代码从 iOS 应用中的 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];
只要图像相当小(例如用设备的相机拍摄),这种方法就可以很好地工作。但是,如果图片太大(6000px^2 或更大),应用程序将在此步骤中耗尽内存:
CGImageRef ref = [rep fullResolutionImage];
我想在应用崩溃之前检测到这种情况,或者(理想情况下)为返回的图像设置最大尺寸。
我知道fullScreenImage 会返回一个较小的图像,但是该应用需要更高的图像分辨率才能进行缩放。
此外,使用资产的字节大小是不可靠的,因为高度压缩的格式(如 JPG)在打包后的大小可能很小,但如果它们的像素大小很高(低细节图像、高度压缩的图像),仍然会消耗过多的内存.
任何有关如何获取图像尺寸并事先检测这种情况以便我可以取消加载并显示错误或如何获得如此大资产的较小版本的任何输入将不胜感激。
【问题讨论】:
标签: iphone objective-c ios cocoa-touch alasset