2010-03-29 151 views
4

我想用照相機捕獲照片後用相機保存帶有按鈕的照片,但我不知道爲什麼我的照片無法在照片庫保存!使用UIImageWriteToSavedPhotosAlbum將圖像保存到相機膠捲

這裏是我的代碼:

-(IBAction)savePhoto{ 

    UIImageWriteToSavedPhotosAlbum(img.image,nil, 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]retain]; 
    [[picker parentViewController]dismissModalViewControllerAnimated:YES]; 
    [picker release]; 
} 

變量名ipcUIImagePickerControllerimgUIIMageView

我的問題是什麼?

回答

4

首先請確保您致電savePhoto。然後你可以添加一個斷言來檢查圖像是否爲零:

- (IBAction) savePhoto { 
    NSParameterAssert(img.image); 
    UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil); 
} 
相關問題