tags:

views:

161

answers:

2

Hi , 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 !

A: 

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

Diederik Hoogenboom
sorry dosnt change anything ! i attached my sample code can you take a look? http://www.multiupload.com/TE9DHMC0H9
Momeks
A: 

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];

Run Loop
sorry , ! didnt work ! can you download my sample code ? :http://www.multiupload.com/TE9DHMC0H9
Momeks