1

我有一个视图,其中有 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];
    }
}

这是我的仪器快照: 仪器快照

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

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

我第三次拍照。
这是应用程序关闭时的日志 日志快照

4

1 回答 1

0

显然,对图像进行下采样仍然使其大小约为 200 kb。下采样后,我将其重新缩放到 37.5%,它工作得很好。谢谢大家

于 2013-03-26T10:27:04.607 回答