应用程序崩溃图像捕获

时间:2012-09-20 10:21:23

标签: iphone ios uiimage uiimagepickercontroller

我正在通过相机拍摄图像。然后我移动到下一个控制器,在那里我显示捕获的图像。我回去捕捉图像屏幕,这个循环持续10到15次。在此之后,当我尝试捕获图像时,应用程序通过提供“低内存警告”而崩溃。 这是代码:

- (IBAction) takePhoto:(id) sender
{
    /*
    tempControl *intermediate=[[tempControl alloc] initWithNibName:@"tempControl" bundle:nil];
    [self.navigationController pushViewController:intermediate animated:YES];
    [intermediate release];
     */
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        imagePickerController= [[UIImagePickerController alloc] init];
        [imagePickerController setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]];
        imagePickerController.delegate = self;
        imagePickerController.sourceType =  UIImagePickerControllerSourceTypeCamera;

        [self presentModalViewController:imagePickerController animated:YES];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Camera Alert" message:@"Device Lacks Camera" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            [alert release];
            alert = nil;
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo{

    [picker dismissModalViewControllerAnimated:NO];
    [picker release];
    picker =nil;
    /*
    cropReciept *recieptToCrop=[[cropReciept alloc] initWithNibName:@"cropReciept" bundle:nil];
    [recieptToCrop setReciept:image];
    [self.navigationController pushViewController:recieptToCrop animated:YES];
    [recieptToCrop release];
     */
    OCRDemoViewController *recieptToCrop=[[OCRDemoViewController alloc] initWithNibName:@"CropTestViewController" bundle:nil];
    [recieptToCrop setImageToCrop:image];
    if ([self.selectedTicketType isEqualToString:@"MAXI QuickPick"]) {
        recieptToCrop.selectedValueOfTicket=50;
        recieptToCrop.drawNumber=self.selectedDrawNumber;
    }
    else if ([self.selectedTicketType isEqualToString:@"JUMBO QuickPick"]) {
        recieptToCrop.selectedValueOfTicket=36;
        recieptToCrop.drawNumber=self.selectedDrawNumber;
    }
    else if ([self.selectedTicketType isEqualToString:@"MEGA QuickPick"]) {
        recieptToCrop.selectedValueOfTicket=24;
        recieptToCrop.drawNumber=self.selectedDrawNumber;
    }
    else if ([self.selectedTicketType isEqualToString:@"REGULAR QuickPick"]) {
        recieptToCrop.selectedValueOfTicket=12;
        recieptToCrop.drawNumber=self.selectedDrawNumber;
    }
    else if ([self.selectedTicketType isEqualToString:@"SUPER QuickPick"]) {
        recieptToCrop.selectedValueOfTicket=18;
        recieptToCrop.drawNumber=self.selectedDrawNumber;
    }

    [self.navigationController pushViewController:recieptToCrop animated:YES];
    [recieptToCrop release];
    recieptToCrop=nil;
}

2 个答案:

答案 0 :(得分:1)

不要在委托回调中释放选择器,而是在下一个运行循环中调度一个块来执行它(你也可以在:0之后使用performSelector)。

还可以使用Instruments ObjectAlloc和Leaks来查看未被解除分配的内容。

答案 1 :(得分:0)

您需要调整图像大小然后再使用它。从相机点击的图像大约是。超过2 mb。尝试调整从相机捕获的图像然后再使用它。 你需要这样做: -

- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo{
UIGraphicsBeginImageContext(size);//640*920 or what ever you think appropriate 
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    [picker dismissModalViewControllerAnimated:NO];
    [picker release];
    picker =nil;
}
And now use finalImage instead of image