Mc.Lover
Mc.Lover

Reputation: 4994

UIImageWriteToSavedPhotosAlbum Problem

i try to save a photo from camera after take a photo with a button .

here is my codes:

-(IBAction)savePhoto{

    UIImageWriteToSavedPhotosAlbum(img.image, nil, nil);    

}

-(IBAction)takePic {

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

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

    img.image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];
}

but i dont know why doesnt save anything !

Upvotes: 0

Views: 1676

Answers (2)

RunLoop
RunLoop

Reputation: 20376

I suspect your image is released before you save it:

img.image = [info objectForKey:UIImagePickerControllerOriginalImage];

The line above returns an autoreleased object. I suggest you retain the image as shown below and then release it when you have saved the image.

img.image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];

Upvotes: 1

diederikh
diederikh

Reputation: 25271

Call [self savePhoto] in -imagePickerController:didFinishPickingMediaWithInfo: after retrieving the image.

Upvotes: 0

Related Questions