0

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

1)我想在我知道如何做的应用程序中拍照 2)现在我只想将该图片保存在应用程序的指定文件夹中。有没有可能这样做。任何帮助将不胜感激。

谢谢

4

1 回答 1

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];
}
}
于 2013-06-22T04:49:02.333 回答