简体   繁体   English

如何从ALAssetsLibrary iOS获取图像实际大小

[英]how to get image real size from ALAssetsLibrary ios

I am trying to select all real size images from ALAssetsLibrary and save in document folder. 我正在尝试从ALAssetsLibrary中选择所有实际尺寸的图像并将其保存在文档文件夹中。 Here is my code to get real size image from ALAssetsLibrary.I get the following error.Is there any other way to get real size image from ALAssetsLibrary? 这是我的代码从ALAssetsLibrary获取真实尺寸图像。出现以下错误。是否还有其他方法从ALAssetsLibrary获取真实尺寸图像?

Connection to assetsd was interrupted or assetsd died 与资产的连接中断或资产死亡

-(void)test{

    for (int i= 0; i < chosenImagesArray.count; i++) {
            NSDictionary *chosenImage = [self.chosenImages objectAtIndex:i];
                ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
                [assetLibrary assetForURL:[chosenImage valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset)
                 {
                     ALAssetRepresentation *rep = [asset defaultRepresentation];

                     unsigned long imageDataSize = (unsigned long)[rep size];
                     imageDataBytes = malloc(imageDataSize);
                     [rep getBytes:imageDataBytes fromOffset:0 length:imageDataSize error:nil];
                     NSData *data = [NSData dataWithBytesNoCopy:imageDataBytes length:imageDataSize freeWhenDone:YES];
                     UIImage *myImg =[UIImage imageWithData:data];

                     //Crop to Standard Size
                     UIImage *readyToWriteImage = [self croppIngimageByImageName:[self fixrotation:myImg ] ];
                     //Write To Document Directory
                     [self writeChosenImage:readyToWriteImage];




                 }
                 failureBlock:^(NSError *err) {
                                  NSLog(@"Error: %@",[err localizedDescription]);

                                 return ;
                  }];

            }

}

You can follow this tutorial "How to get meta data of an Image" as size is in the metadata of image so you can get size from returned dictionary of meta data this is the link http://blog.codecropper.com/2011/05/getting-metadata-from-images-on-ios/ 您可以按照本教程“如何获取图像的元数据”进行操作,因为大小位于图像的元数据中,因此您可以从返回的元数据字典中获取大小,这是链接http://blog.codecropper.com/2011/ 05 /获取元数据-从图像上-IOS /

thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM