2010-03-04 94 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

相关问题