使用ALAsset来自GRKPhoto的UIImage [英] UIImage from GRKPhoto using ALAsset

查看:102
本文介绍了使用ALAsset来自GRKPhoto的UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 grabKit ,以便允许用户将其Instagram,Facebook和本地图片导入我的应用当照片是本地照片时,问题就来了。在这种情况下,我使用一种当用户选择照片时有效的方法。

I'm using grabKit in order to allow users to import their Instagram, Facebook and local pictures to my app. The problem comes when the photo is local. In this case, I use a method that works when the user selects the photo.

为此找到的标准代码如下:

The standard code I found in order to do so is the following:


- (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.
                 }];
}

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

By doing some debugging, I found that the app crashes when I try to get the CGImageRef from the ALAsset, ergo, in this line: CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage];.

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

If it can help to solve my issue, the message I get in the console is:


*** 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

感谢您的时间和

推荐答案

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

Usually CALayerInvalidGeometry and NAN results from invalid setting of CALayer frame, which in turn can be set by view.frame. It maybe that somewhere the layer position / transform is being set incorrectly. Since you are not doing this directly it seems to be a bug with Grabkit. File it here.

您可以考虑进入 CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage]; 使用F7向 Grabkit 。

You can consider going inside CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage]; using F7 to provide more information about the crash to Grabkit.

这篇关于使用ALAsset来自GRKPhoto的UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆