我正在将图片转换为NSData
。对于以前的iOS
版本,它没问题。但现在它的崩溃在iOS 10.0 。
我认为崩溃在这里:
UIImage * image=[selectedPhotos objectAtIndex:i];
NSData *imageData =[[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 1.0)];
有人,建议我这样做:CGImageDestinationFinalize or UIImageJPEGRepresentation - Crash when saving a large file on IOS 10
我称之为:
UIImage * image=[self convertImage:[selectedPhotos objectAtIndex:i]]; //Dont worry, i am getting the image from array
imageData=[[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 1.0)];
方法:
-(UIImage *)convertImage:(UIImage *)sourceImage{
UIGraphicsBeginImageContext(sourceImage.size);
[sourceImage drawInRect:CGRectMake( 0, 0, sourceImage.size.width, sourceImage.size.height)];
UIImage *targetImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return targetImage;
}
仍然显示问题:
- [NSConcreteMutableData CGImage]:无法识别的选择器发送到实例0x60000005dfd0
仍在崩溃。有解决方案吗
答案 0 :(得分:0)
看起来[selectedPhotos objectAtIndex:i]
没有返回UIImage
。