0

我有一个 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];
});
4

1 回答 1

1

您可以在图像滚动到屏幕之前预加载图像。您正在预加载的图像可以在后台线程上完成并保存到NSCache实例中。缓存将自动清除(如果您设置countLimit或设备内存不足),因此当您预加载时,请检查缓存中的项目并在需要时在后台线程上加载。

于 2013-10-21T14:04:00.197 回答