我有一个ALAssetRepresentation问题。有一张桌子以高分辨率显示画廊图像。 fullScreenImage方法占用了太多时间,表格运行缓慢。如何实现更快的加载?例如,图库图片加载会立即发生在https://itunes.apple.com/us/app/print-studio-print-photos/id601882801?mt=8中,他们怎么可能这样做?
ALAsset *result = photos[_index];
UIImageView *photoView = (UIImageView*)[contentView viewWithTag:PHOTO_VIEW];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
ALAssetRepresentation *represintation = [result defaultRepresentation];
NSURL* aURL = represintation.url;
[library assetForURL:aURL resultBlock:^(ALAsset *asset){
UIImage *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage] scale:0.3 orientation:UIImageOrientationUp];
copyOfOriginalImage = [copyOfOriginalImage imageByScalingAndCroppingForSize:CGSizeMake(600, 600)];
dispatch_async(dispatch_get_main_queue(), ^{
[photoView setImage:newImg];
[photoView setNeedsDisplay];
});
}
failureBlock:nil];
});
答案 0 :(得分:1)
您可以在将图像滚动到屏幕上之前预先加载图像。您正在预加载的图像可以在后台线程上完成并保存到NSCache
实例中。缓存将自动清除(如果您设置countLimit
或设备内存不足),因此在预加载时,检查缓存中的项目并在必要时加载后台线程。