【问题标题】:ALAssetRepresentation fullScreenImageALAssetRepresentation fullScreenImage
【发布时间】:2013-10-21 13:58:25
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c alasset


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 2011-05-18
      • 2015-02-21
      相关资源
      最近更新 更多