tags:

views:

18

answers:

0

My aim is take the photo from the camera and need to save it in the camera roll.

For that the code I wrote is:

- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject  
{  
isCamera = YES;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *picker = [[[UIImagePickerController alloc] init]autorelease];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.allowsEditing = YES;
    picker.delegate = self;
    [controller presentModalViewController:picker animated:YES];
}
return YES; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
if(isPhotoLib == YES)
{
    [self useImage:img];
}
else if(isCamera == YES)
{
    data1 = [UIImageJPEGRepresentation(img, 1.0) copy];
    stillImage = [UIImage imageWithData:data1];
    alert2 = [[UIAlertView alloc] initWithTitle:@"CorkIt" message:@"Do you want to save this image in Camera roll?"
                                       delegate:self cancelButtonTitle:@"YES" otherButtonTitles: @"NO",nil];
    [alert2 show];  
    [alert2 release];
}   
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView == alert2)
{
    if (buttonIndex == 0)
    {
        UIImage *newImg = [UIImage imageWithData:data1];
        [self savePhoto:newImg];
    }   
    else if(buttonIndex == 1)
    {
        UIImage *newImg = [UIImage imageWithData:data1];
        [self useImage:newImg];
        [self reloadView];
    }
}
else if(alertView == alert)
{
    if (buttonIndex == 0)
    {
        CorkItAppDelegate* appDelegate = (CorkItAppDelegate*)[[UIApplication sharedApplication] delegate];
        [appDelegate deleteFromEventsList:event];
        [self.navigationController popViewControllerAnimated:YES];
    }   
}
}


-(void)useImage:(UIImage *)theImage
{
if(isWinePic == YES)
{
    event.eventWinePic = UIImagePNGRepresentation(theImage);
}
else if(isWinePic == NO)
{
    event.eventPic = UIImagePNGRepresentation(theImage);
}
[tableView reloadData];
}

-(IBAction)savePhoto:(UIImage *)theImage
{
NSData *data = UIImageJPEGRepresentation(theImage, 1.0);

printf("\n still image length:%d",[data length]);

NSParameterAssert(theImage);
UIImageWriteToSavedPhotosAlbum(theImage,nil, nil, nil); 
UIAlertView *newalert = [[UIAlertView alloc]initWithTitle:@"Image Saved !" 
                                               message:@"Your image has been saved In Camera roll." 
                                              delegate:self
                                     cancelButtonTitle:@"Ok" 
                                     otherButtonTitles:nil];
[newalert show];
[newalert release];
//UIImageWriteToSavedPhotosAlbum(stillImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

}

Here when I taken the photo from camera it was saving into the camera roll but when I use the photo taken by camera for future use the application is terminating by showing memory warning.The application is terminating only when I select the image which was taken from the camera.

Can any one suggest how to get rid of this?