2010-03-04 149 views
1

我工作的項目之一,我必須在iPhone設備照片庫中保存捕獲的圖像。如何從iPhone設備照片庫中的相機中保存拍攝圖像?

我想問問如何通過code.Here實現這個下面我爲我貼的代碼是什麼: -

- (空)imagePickerController:(*的UIImagePickerController)選擇器didFinishPickingMediaWithInfo:(NSDictionary的*)信息{

[picker dismissModalViewControllerAnimated:YES]; 
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
imgglobal =imageView.image; 
NSString *newFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"~/Users/abc/Library/Application Support/iPhone Simulator/User/Applications/SAVE_IMAGE_TEST1.JPG"]; 
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0); 
NSData *data = imageData; 
if (imageData != nil) { 
    [imageData writeToFile:newFilePath atomically:YES]; 
} 
if ([[NSFileManager defaultManager] createFileAtPath:@"~/Users/abc/Library/Application Support/iPhone Simulator/User/Applications/SAVE_IMAGE_TEST1.JPG" contents:data attributes:nil]) 
{ 
    UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Image was successfully saved to the Photo Library." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; 
    [successAlert show]; 
    [successAlert release]; 
} else { 
    UIAlertView  *failureAlert = [[UIAlertView alloc] initWithTitle:@"Failure" message:@"Failed to save image to the Photo Library." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; 
    [failureAlert show]; 
    [failureAlert release]; 
}  

}

但我的應用程序顯示故障發生警報,​​請給我正確的代碼將捕獲的圖像保存到iPhone設備照片庫。

在此先感謝其非常緊迫

+0

@AmanGupta007我面臨同樣的問題,請給我一些建議如何可能? – 2014-03-26 10:32:58

回答

1

這是一個一行(不包括錯誤處理)。請致電UIImageWriteToSavedPhotosAlbum()

+0

BegemannHi我面臨同樣的問題,我需要將拍攝照片從相機保存到iphone設備庫。所以用戶可以直接從他的設備上覆制。請給我一些建議,如何可能?謝謝 – 2014-03-26 10:35:22

相關問題