如何在应用iOS中保存捕获的照片?

时间:2013-06-22 04:18:31

标签: ios uiimagepickercontroller

我正在制作一个iphone应用程序

1)我想在我知道该怎么做的应用程序中拍照 2)现在我想将该图片仅保存在应用程序的指定文件夹中。是否可以这样做。任何帮助都将非常感激。

谢谢

1 个答案:

答案 0 :(得分:3)

试试这个

您可以在 UIImagePickerControllerDelegate 委托实施中使用以下代码

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

//obtaining saving path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"latest_photo.png"];

//extracting image from the picker and saving it
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];   
if ([mediaType isEqualToString:@"public.image"]){
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *webData = UIImagePNGRepresentation(editedImage);
    [webData writeToFile:imagePath atomically:YES];
}
}