我正在尝试从ALAssetsLibrary中选择所有实际大小的图像并保存在文档文件夹中。这是我从ALAssetsLibrary获取实际大小图像的代码。我得到以下错误。还有其他方法可以从ALAssetsLibrary获取实际大小的图像吗?
资产的连接被中断或资产已经死亡
-(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 ;
}];
}
}
答案 0 :(得分:0)
您可以按照本教程“如何获取图像的元数据”,因为大小在图像的元数据中,因此您可以从返回的元数据字典中获取大小,这是链接http://blog.codecropper.com/2011/05/getting-metadata-from-images-on-ios/
感谢