拍摄第三张照片后,应用程序崩溃 - iOS

时间:2013-03-26 09:19:44

标签: ios objective-c memory camera

我有一个视图,其中有6个图像视图。我使用相机UIImagePickerController设置图像。每次我选择第3张图片时,我的应用程序总是崩溃,当我检查仪器时,没有泄漏。怎么了? 这是我的代码:

- (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];
    }
}

这是我的仪器快照: Instrument's snapshot

编辑: 应用程序在处理行崩溃

NSData* imageData = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.0001f);

我第三次拍照。
这是应用关闭时的日志 log snapshot

1 个答案:

答案 0 :(得分:0)

显然,对图像进行下采样仍然使其大小约为200 kb。 在下采样之后,我将它重新调整为37.5%并且它工作得很好。全部