2010-03-27 55 views
0

我嘗試使用按鈕拍攝照片後從相機保存照片。UIImageWriteToSavedPhotosAlbum問題

這裏是我的代碼:

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

,但我不知道爲什麼犯規保存任何東西!

+0

誰調用了'-savePhoto'? – kennytm 2010-03-27 10:45:58

回答

1

我懷疑你保存它之前,你的形象被釋放:

img.image = [info objectForKey:UIImagePickerControllerOriginalImage];

線之上返回一個自動釋放的對象。我建議你保留下圖所示的圖像,然後在保存圖像時將其釋放。

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

+0

對不起,!沒有工作!你能下載我的示例代碼嗎? : http://www.multiupload.com/TE9DHMC0H9 – Momi 2010-03-27 12:17:07

0

檢索圖像後調用[self savePhoto]-imagePickerController:didFinishPickingMediaWithInfo:

+0

抱歉dosnt改變任何東西!我附上我的示例代碼,你可以看看嗎? http://www.multiupload.com/TE9DHMC0H9 – Momi 2010-03-27 11:51:45

相關問題