2

我在右上角有一个 UICollectionView 和一个条形按钮(CameraViewController1:UICollectionViewController)。流程是当我拍照时它移动到一个可以裁剪图像的新视图控制器。用户在选择任何一个后有两个选项使用和取消此选项将图像返回到集合视图并像单元格一样排列。我想拍很多照片。但我最多只能拍摄 3 张照片,因为应用程序立即崩溃并显示消息“应用程序因内存而终止压力”。但最糟糕的是,当我在运行 iOS 7 的 iPhone 5 中测试相同的应用程序时,没有发生崩溃。当我在运行 iOS 7 的 iPhone 4 中测试相同的应用程序时,它会崩溃并产生收到的内存警告。

这是我的代码

- (IBAction)TakeaPhoto:(id)sender {

    [[UIApplication sharedApplication]setStatusBarHidden:FALSE withAnimation:NO];

    gallery=0;
    picker1 = [[UIImagePickerController alloc] init];
    picker1.delegate = self;
    self.resizeableCropArea =YES;
    self.cropSize=CGSizeMake(300,350);
    //picker1.allowsEditing = YES;
    picker1.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker1 animated:YES completion:NULL];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [self dismissViewControllerAnimated:YES completion:NULL];

    UIImage *image =  [info objectForKey: UIImagePickerControllerOriginalImage];

    image_cap = [self imageTemp:image scaledToSize:CGSizeMake(320, 370)]; 


    dataTemp = UIImageJPEGRepresentation(image,0.0);

    CropViewController *cropController = [[CropViewController alloc] init];

    cropController.sourceImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    Original_img = UIImageJPEGRepresentation(cropController.sourceImage,0.0);

    [original_image addObject:[UIImage imageWithData:Original_img]]; //original_image Nsmutablearray

    NSLog(@"source image=%@",cropController.sourceImage);

    cropController.resizeableCropArea = self.resizeableCropArea;

    cropController.cropSize = self.cropSize;

    cropController.delegate = self;

    Cancel_Image= cropController.sourceImage;

    [self.navigationController pushViewController:cropController animated:YES];

}
4

1 回答 1

0

@Ramanan R R, I m totally agree with the @Rushabh's comment.. You are allocating that UIImagePickerController for many more times, as TakeaPhoto method call you are allocating UIImagePickerConrtoller, it is not necessary to allocate that multiple times. It makes memory spoilage, thats why your app is going to terminate or crash.. Just allocate that one time in viewDidLoad, make sure one more thing that, do UIImagePickerController as a strong property, because in past it took my whole day to solve issue...

Hope this will work for you and your app will run smoothly...:)

于 2014-03-14T12:19:34.470 回答