3

我想使用 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 只是一直显示加载?

有任何想法吗 ?提前致谢

4

1 回答 1

0

也许不是最快和最有效的方法,但它解决了问题。请使用 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;
于 2013-09-30T17:53:05.400 回答