ios - 使用 ALAsset 来自 GRKPhoto 的 UIImage

标签 ios objective-c uiimage alasset cgimageref

我正在使用 grabKit为了让用户将他们的 Instagram、Facebook 和本 map 片导入我的应用程序。当照片是本地的时,问题就来了。在本例中,我使用了一种在用户选择照片时起作用的方法。

我找到的标准代码如下:

- (void)picker:(GRKPickerViewController*)picker didSelectPhoto:(GRKPhoto *)photo{

    [popover dismissPopoverAnimated:YES];

    GRKImage *originalImage = [photo originalImage];

    NSLog(@" the URL of the original image of the first selected photo is : %@", originalImage.URL );
    NSLog(@" the size of this image is : %d x %d ", originalImage.width, originalImage.height );

    // If the url begins with assets-library://
    if ( [[originalImage.URL absoluteString] hasPrefix:@"assets-library://"] ){

        // Instantiate a library
        ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

        // Ask for the "Asset" for the URL. An asset is a representation of an image in the Photo application.
        [library assetForURL:originalImage.URL
                 resultBlock:^(ALAsset *asset) {

                     // Here, we have the asset, let's retrieve the image from it
                     CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage];

                     // From the CGImage, let's build an UIImage
                     UIImage * fullResImage = [UIImage imageWithCGImage:imgRef];

                     NSLog(@" The UIImage for URL %@ is %@", originalImage.URL, fullResImage);

                 } failureBlock:^(NSError *error) {
                     // Something wrong happened.
                 }];
}

通过调试,我发现当我尝试从 ALAsset 获取 CGImageRef 时,应用程序崩溃了,因此,在这一行中:CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage];.

如果它可以帮助解决我的问题,我在控制台中得到的消息是:

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 653]'

*** First throw call stack:

(0x42f8012 0x2ad9e7e 0x42f7deb 0x161ee0b 0x161efa5 0x161f6eb 0x174fe53 0x18191c0 0x181941a 0x21fad 0x219f1 0x13de70 0xf3c03 0x1c0f42f 0x1c21182 0x1c21394 0x2aed705 0x181b93c 0x181b9ac 0x2aed705 0x181b93c 0x181b9ac 0x19d51d3 0x42c0afe 0x42c0a3d 0x429e7c2 0x429df44 0x429de1b 0x3b9d7e3 0x3b9d668 0x170dffc 0x69432 0x30f5)

libc++abi.dylib: terminate called throwing an exception

感谢您的时间和兴趣!

最佳答案

通常 CALayerInvalidGeometryNAN 是由于 CALayer 框架的无效设置导致的,而 CALayer 框架又可以由 view.frame 设置。可能某处图层位置/变换设置不正确。由于您没有直接执行此操作,因此它似乎是 Grabkit 的错误。归档 here .

您可以考虑进入 CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage]; 使用 F7 向 Grabkit 提供有关崩溃的更多信息。

关于ios - 使用 ALAsset 来自 GRKPhoto 的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17530222/

相关文章:

iPhone SDK : How to add an outline to UILabel's text

ios - 如何将日期选择器的值保存到变量中?

ios - 为什么 UIImage 在 Slider 中裁剪后变得模糊?

ios - 提供 native iOS 文档扫描仪?

ios - 在 iOS 中从 plist 向字符串添加换行符

objective-c - 在 HTML5 文档中加载视频时,WebView 的自定义 NSURLProtocol 类不起作用

ios - 从静态子项目访问委托(delegate)

objective-c - 如何向 lldb 控制台中的对象发送消息?

ios - UIButton 图像只改变一个按钮

objective-c - 加快检查点像素颜色的速度