开发者

UIImageWriteToSavedPhotosAlbum Problem

开发者 https://www.devze.com 2022-12-24 16:09 出处:网络
i try to save a photo from camera after take a photo with a button . here is my codes: -(IBAction)savePhoto{

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

here is my codes:

-(IBAction)savePhoto{

    UIImageWriteToSavedPhotosAlbum(开发者_如何学Cimg.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 !


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消