Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Using multiple times UIImagePickerController+Camera crash app

swayamswayam Posts: 8New Users Noob
edited August 2013 in iOS SDK Development

After lots of experiment and after lots of suggestion still I am unable to fix this issue. If I take around 2 to 3 picture using UIImagePickerController Camera or library, I am starting to get Received memory warning in the Xcode log and after then when I try to take 4th or 5th picture the app Crashes.i have use camera picture in ocr library for image to text.

If anybody solved this issue, please help me out to solve this issue.

i have use below code.
- (IBAction)TakePhoto:(id)sender {
    @try {
      
                   
        
            if(mediaPicker==nil)
            {
                self.mediaPicker = [[UIImagePickerController alloc] init];
                self.mediaPicker.delegate=self;
                self.mediaPicker.allowsEditing = YES;
                self.mediaPicker.videoQuality=UIImagePickerControllerQualityTypeLow;
                self.mediaPicker.showsCameraControls=NO;
            }
           
            
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
               
                
                UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:
                                              @"Take a photo or choose existing, and use the control to center the announce"
                                                                         delegate: self                                                        cancelButtonTitle:@"Cancel"
                                                           destructiveButtonTitle:nil
                                                                otherButtonTitles:@"Take photo", @"Choose Existing", nil];
                [actionSheet showInView:self.view];
                
               
                
            } else {
                self.mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                [self presentViewController:mediaPicker animated:YES completion:nil];                
            }

        
    }
    @catch (NSException *exception) {
        NSLog(@"%@",exception.description);
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    @try {
        
            if(buttonIndex != actionSheet.cancelButtonIndex)
            {
                if (buttonIndex == 0) {
                     self.mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                } else if (buttonIndex == 1) {
                    self.mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                }
            
                [self presentViewController:self.mediaPicker animated:YES completion:nil];
                
            }
            else
            {
                [self dismissViewControllerAnimated:YES completion:nil];
                
            }
            
            // });

    }
    @catch (NSException *exception) {
        NSLog(@"%@",exception.description);
    }
  }
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    @try {
        
            //I take the coordinate of the cropping
            CGRect croppedRect=[[info objectForKey:UIImagePickerControllerCropRect] CGRectValue];
            
            UIImage *original=[info objectForKey:UIImagePickerControllerOriginalImage];
            original = [UIImage imageWithCGImage:original.CGImage scale:0.25 orientation:original.imageOrientation];
            CGFloat compression = 0.9f;
            NSData *imageData = UIImageJPEGRepresentation(original, compression);
            while ([imageData length] > 700000 && compression > 0.1) {
                compression -= 0.1;
                imageData = UIImageJPEGRepresentation(original, compression);
                
            }
           original=[UIImage imageWithData:imageData];
            UIImage *rotatedCorrectly;
            
            if (original.imageOrientation!=UIImageOrientationUp)
                rotatedCorrectly=[original rotate:original.imageOrientation];
            else rotatedCorrectly=original;
            
            
           // CGImageRef ref= CGImageCreateWithImageInRect(rotatedCorrectly.CGImage, CGRectMake(0,50,720, 721));
            CGImageRef ref= CGImageCreateWithImageInRect(rotatedCorrectly.CGImage, croppedRect);
            self.takenImage= [UIImage imageWithCGImage:ref];
            
            self.resultView.image=[self takenImage];
            self.processedImage=[self takenImage ];
            
            self.read.hidden=NO;
            CGImageRelease(ref);
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
    @catch (NSException *exception) {
        NSLog(@"%@",exception.description);
    }
   
}


Replies

  • dev666999dev666999 Posts: 3,632New Users @ @ @ @ @
    Use Instruments and test for leaks and allocations.

    If you're not sure how to use them, Google...xcode instruments.
  • SundialSoftSundialSoft Posts: 307Registered Users @ @
    I'm pretty sure I found the solution to this on Stack Overflow. As I remember it's just a tidying up issue.
Sign In or Register to comment.