简体   繁体   中英

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. 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?

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/

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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