【问题标题】:Display an ALAsset using QLPreviewController使用 QLPreviewController 显示 ALAsset
【发布时间】:2013-02-09 21:35:40
【问题描述】:

我想使用 QLPreviewController 显示照片流中的 ALAsset QLPreviewController 需要一个 NSURL 来显示项目

当它是一个文件 URL 时,这很有效,例如 /var/mobile/Applications/5374......9E0/Documents/image33.png

我有 ALAsset 但是使用 [[asset defaultRepresentation] url] 给了我一个 NSURL 类型
assets-library://asset/asset.JPG?id=00000000-0000-0000-0000-000000000075&ext=JPG

但这不显示 QLPreviewController 只是一直显示加载??

有什么想法吗? 提前致谢

【问题讨论】:

    标签: ios alasset qlpreviewcontroller


    【解决方案1】:

    也许不是最快和最有效的方法,但它解决了问题。请使用 NSFilemanager 代替 NSTemporaryDirectory,如文档中所示 :-) 确保链接到 ImageIO.framework

        #import <ImageIO/ImageIO.h>
    
        ....
        NSURL *outURLToUseWithQLPreviewController = nil;
    
        ALAsset *myAsset = ... // received somehow
        ALAssetRepresentation *represent = myAsset.defaultRepresentation;
        CGImageRef representFullScreen = represent.fullScreenImage;
    
        NSString *tempDir = NSTemporaryDirectory();
        NSString *imagePath = [tempDir stringByAppendingPathComponent:represent.filename];
        NSURL *tempURL = [NSURL fileURLWithPath:imagePath];
    
        CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)(tempURL), (__bridge CFStringRef)(represent.UTI), 1, NULL);
        CGImageDestinationAddImage(destination, representFullScreen, nil);
        if ( CGImageDestinationFinalize(destination) ) {
            outURLToUseWithQLPreviewController = tempURL;
        }
        return outURLToUseWithQLPreviewController;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多