views:

55

answers:

1

I have an app that builds a slideshow from user images. They can grab from their library or take a picture. I have found that repeated use of grabbing an image from the library is fine. But repeated use of taking a picture causes erratic behavior. I have been getting crashes but mostly what happens seems to be a reloading of the view after "didFinishPickingMediaWithInfo", which messes things up.

I have no leaks and it seems to be releasing properly after each picture is taken. I am resizing the image and saving it in a data base. Is anyone else running into this situation? Was the camera not designed to be called this often?

A: 

Sorry for the mix up. It's not continuos, it's take a picture, remove and release the camera, then the user selects choice A, B or C (they are prompted throughout to make selections on many things) then they can take another picture, remove and release the camera...etc...and this happens several times while they complete all the data entry.

After they select the camera I call this code. I am not releasing the image picker in the dealloc method.

- (void)openCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{

    imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}

}

After they "USE" a picture taken from the camera I call the following code. It resized the image based on the original size of the image.

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

UIImage *tempCameraImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [picker dismissModalViewControllerAnimated:YES];

    CGFloat originalSize = tempCameraImage.size.width * tempCameraImage.size.height;
    NSLog(@"Original Size %f", originalSize);
    if (originalSize > 2500000.0) {
        CGSize size = tempCameraImage.size;
        CGRect rect = CGRectMake(0.0, 0.0, .23 * size.width, .23 * size.height);
        UIGraphicsBeginImageContext(rect.size);
        [tempCameraImage drawInRect:rect];
        theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGFloat totalSize = theImage.size.width * theImage.size.height;
        NSLog(@"Final Camera Size %f", totalSize);
        [self resizeImageCamera];
        return;
    }
    else {
        CGSize size = tempCameraImage.size;
        CGRect rect = CGRectMake(0.0, 0.0, .27 * size.width, .27 * size.height);
        UIGraphicsBeginImageContext(rect.size);
        [tempCameraImage drawInRect:rect];
        theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGFloat totalSize = theImage.size.width * theImage.size.height;
        NSLog(@"Final Camera Size %f", totalSize);
        [self resizeImageCamera];
        return;
    }

}

-(void)resizeImageCamera {
if (editingImage1) {
    NSManagedObject *image = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:slideshow.managedObjectContext];
    slideshow.image = image;
    [image setValue:theImage forKey:@"image"];

    CGSize size = theImage.size;
    CGRect rect = CGRectMake(0.0, 0.0, .15 * size.width, .15 * size.height);
    UIGraphicsBeginImageContext(rect.size);
    [theImage drawInRect:rect];
    slideshow.thumbnailImage1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self finishCameraImage];
    return;
}

}

-(void)finishCameraImage {

if (editingImage1) {
    keyInt = @"2";
    [editedObject setValue:keyInt forKey:@"script1"];
    pictureView.alpha = 0;
    self.navigationItem.rightBarButtonItem = nil;
    editedFieldKey = @"line2Int";
    editedFieldName = NSLocalizedString(@"line2Int", @"display name for line2");
    self.title = editedFieldName;
    linePicker.hidden = NO;

}

I realize I am doing a lot to this image. If I put in a couple of delays would that help?

Sam