使用 ALAsset 来自 GRKPhoto 的 UIImage

2023-12-27

我在用着grabKit https://github.com/pierrotsmnrd/grabKit为了允许用户将他们的 Instagram、Facebook 和本地图片导入到我的应用程序中。当照片是本地时就会出现问题。在本例中,我使用了一种在用户选择照片时起作用的方法。

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



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

通过进行一些调试,我发现当我尝试获取CGImageRef来自ALAsset,因此,在这一行中: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
  

感谢您的时间和兴趣!


Usually CALayerInvalidGeometry and NANCALayer 框架的无效设置导致的结果,而 CALayer 框架又可以通过以下方式设置view.frame。可能某个地方的图层位置/变换设置不正确。由于您没有直接执行此操作,因此这似乎是一个错误Grabkit。归档here https://github.com/pierrotsmnrd/grabKit/issues.

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 ALAsset 来自 GRKPhoto 的 UIImage 的相关文章

随机推荐