拍摄第三张照片后应用程序崩溃 - iOS
Posted
技术标签:
【中文标题】拍摄第三张照片后应用程序崩溃 - iOS【英文标题】:app crashing after taking 3rd picture - iOS 【发布时间】:2013-03-26 09:19:44 【问题描述】:我有一个视图,其中有 6 个图像视图。我使用相机 UIImagePickerController 设置图像。每次我选择第三张图片时,我的应用程序总是崩溃,当我检查仪器时,没有泄漏。怎么了? 这是我的代码:
- (void)openCamera
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
NSData* imageData = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.0001f);
[self dismissViewControllerAnimated:true completion:nil];
if ([_selectedButton isEqualToString:@"headOffice"])
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgHeadOffice"];
//_imgHeadOffice = [UIImage imageWithData:imageData];
_imgViewHeadOffice.image = [UIImage imageWithData:imageData];
else if ([_selectedButton isEqualToString:@"siteOffice"])
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgSiteOffice"];
//_imgSiteOffice = [UIImage imageWithData:imageData];
_imgViewSiteOffice.image = [UIImage imageWithData:imageData];
else if ([_selectedButton isEqualToString:@"roadCondition"])
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgRoadCondition"];
//_imgRoadCondition = [UIImage imageWithData:imageData];
_imgViewRoadCondition.image = [UIImage imageWithData:imageData];
else if ([_selectedButton isEqualToString:@"vehicle"])
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgVehicle"];
//_imgVehicle = [UIImage imageWithData:imageData];
_imgViewVehicle.image = [UIImage imageWithData:imageData];
else if ([_selectedButton isEqualToString:@"installedTire"])
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgInstalledTire"];
//_imgInstalledTire = [UIImage imageWithData:imageData];
_imgViewInstalledTire.image = [UIImage imageWithData:imageData];
else if ([_selectedButton isEqualToString:@"tireScrap"])
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgTireScrap"];
//_imgTireScrap = [UIImage imageWithData:imageData];
_imgViewTireScrap.image = [UIImage imageWithData:imageData];
这是我的 Instruments 快照:
编辑: 应用程序在处理行时崩溃
NSData* imageData = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.0001f);
我第三次拍照。 这是应用程序关闭时的日志
【问题讨论】:
这些图片是一样的吗?可能是它们的尺寸很大,而您的应用想要分配一个巨大的缓冲区,所以 ios 将其杀死 请在放置异常断点后也提供堆栈跟踪 不,它们不一样。我已将其大小调整为 0.0001f 质量(请参阅我的代码) 当您使用模拟器时,没有此类问题。在编辑方案中启用僵尸对象,您可以找出导致崩溃的对象 让我们continue this discussion in chat 【参考方案1】:显然,对图像进行下采样后仍会使其大小约为 200 kb。 下采样后,我将其重新缩放到 37.5%,它工作得很好。谢谢大家
【讨论】:
以上是关于拍摄第三张照片后应用程序崩溃 - iOS的主要内容,如果未能解决你的问题,请参考以下文章
从同一个 AVCaptureSession 拍摄视频和照片时应用程序崩溃?