0

尝试从NSDocumentsDirectoryiPhone 加载文件时,我无法使用我拥有的路径字符串创建图像源。

我收到错误消息“ <Error>: ImageIO: CGImageSourceCreateWithURL CFURLCreateDataAndPropertiesFromResource failed with error code -15.”,这是一个kCFURLImproperArgumentsError.

但是,我找不到“正确”的论点可能是什么。一个示例路径是:“ /var/mobile/Applications/36D76BDF-72EC-4180-9246-CF1F50CF396C/Documents/2013080110555532Image.tiff

在我的问题How to save a TIFF...中,我现在记录了如何将文件写入NSDocumentsDirectory. 再次感谢各位的帮助。

现在我尝试再次阅读它们。我认为阅读就像写作,只是镜像。
这些文件约为 20MB - ...咳咳,...每个!- 这也可能是一个问题......

这是一个代码片段(感谢Ganapathy回答),它实际上给了我一个要显示的图像:

if ([self pathLastRawDataSave])
{
    UIImage *anImage = [UIImage imageWithContentsOfFile:[self pathLastRawDataSave]];

    if (NULL != anImage)
    {
        [[self imageView] setImage:anImage];
    }
}

然而,它总是比一个小例子更复杂,而且我还需要元数据(和图像的缩略图),所以我担心我会回来做这项CGImageSource工作,毕竟。

赫里卡!我找到了!缺少的链接是方法 fileURLWithPath 除此之外,我没有缓存,也没有使用创建选项字典进行图像检索。

这实际上是有效的:

if ([self pathLastRawDataSave])
{
    NSURL* imageFileURL = [NSURL fileURLWithPath:[self pathLastRawDataSave]];

    CFURLRef imageFileURLRef = (__bridge CFURLRef)imageFileURL; // bridged from NS-Object, no release!

    NSDictionary* sourceOptions = @{(id)kCGImageSourceShouldCache: (id)kCFBooleanFalse,
                                    (id)kCGImageSourceTypeIdentifierHint: (id)kUTTypeTIFF};

    CFDictionaryRef sourceOptionsRef = (__bridge CFDictionaryRef)sourceOptions; // bridged from NS-Object, no release!

    CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageFileURLRef, sourceOptionsRef);


    if (NULL != imageSource)
    {
        // create the image from the file
        CGImageRef imageData = CGImageSourceCreateImageAtIndex(imageSource, 0, sourceOptionsRef);

        // release core foundation object
        CFRelease(imageSource);
    }
    else
    {
        // Error opening image file
        HLSLoggerFatal(@"Image source could not be accessed at path %@", [self pathLastRawDataSave]);
    }
}
4

1 回答 1

0

赫里卡!我找到了!缺少的链接是方法 fileURLWithPath 除此之外,我没有缓存,也没有使用创建选项字典进行图像检索。

这实际上是有效的:

if ([self pathLastRawDataSave])
{
    NSURL* imageFileURL = [NSURL fileURLWithPath:[self pathLastRawDataSave]];

    CFURLRef imageFileURLRef = (__bridge CFURLRef)imageFileURL; // bridged from NS-Object, no release!

    NSDictionary* sourceOptions = @{(id)kCGImageSourceShouldCache: (id)kCFBooleanFalse,
                                    (id)kCGImageSourceTypeIdentifierHint: (id)kUTTypeTIFF};

    CFDictionaryRef sourceOptionsRef = (__bridge CFDictionaryRef)sourceOptions; // bridged from NS-Object, no release!

    CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageFileURLRef, sourceOptionsRef);


    if (NULL != imageSource)
    {
        // create the image from the file
        CGImageRef imageData = CGImageSourceCreateImageAtIndex(imageSource, 0, sourceOptionsRef);

        // release core foundation object
        CFRelease(imageSource);
    }
    else
    {
        // Error opening image file
        HLSLoggerFatal(@"Image source could not be accessed at path %@", [self pathLastRawDataSave]);
    }
}
于 2013-08-01T15:39:19.733 回答