【问题标题】:Getting Error Trying to Create AspectRatioThumbnail from Image I/O尝试从图像 I/O 创建 AspectRatioThumbnail 时出错
【发布时间】:2012-05-14 20:25:40
【问题描述】:

我正在尝试从 iOS5 之前的 ALAsset 创建纵横比缩略图(ALAssetDefaultRepresentation aspectRatioThumbnail 直到 ios5 才实现)。我有以下代码,由于某种原因它给了我一个错误:

CGImageRef imref;
    NSURL* url = [self.photoAsset.defaultRepresentation url];
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                       (id)kCFBooleanTrue, kCGImageSourceShouldAllowFloat,
                       (id)kCFBooleanTrue, kCGImageSourceCreateThumbnailWithTransform,
                       (id)kCFBooleanTrue, kCGImageSourceCreateThumbnailFromImageAlways,
                       [NSNumber numberWithInteger:1024], kCGImageSourceThumbnailMaxPixelSize, nil];
    CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
    imref = CGImageSourceCreateThumbnailAtIndex(src, 0, (CFDictionaryRef) dictionary);

具体来说我得到:

ImageIO: <ERROR>  CGImageSourceCreateWithURL CFURLCreateDataAndPropertiesFromResource failed with error code -11.ImageIO: <ERROR>  CGImageSourceCreateThumbnailAtIndex image source parameter is nil

有人知道怎么回事吗?

【问题讨论】:

标签: iphone ios cocoa-touch core-graphics


【解决方案1】:

问题在于您传递给创建“src”的url, 检查url 是否有效,并且此网址存在一些图片。

【讨论】:

  • 我认为我检索的 URL 不是用于图像,而是用于资产本身。知道如何获取图片网址吗?
猜你喜欢
  • 2015-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
  • 1970-01-01
相关资源
最近更新 更多