【问题标题】:Save image from iPhone camera directly to documents folder and not to camera roll?将 iPhone 相机中的图像直接保存到文档文件夹而不是相机胶卷?
【发布时间】:2011-10-29 22:19:19
【问题描述】:

我正在尝试弄清楚如何使用 iPhone 相机拍摄图像并将其直接保存到应用程序文档文件夹中,如果可能的话不要保存在相机胶卷中。

我有我的应用程序显示相机,我可以将图像保存到相机胶卷,但我想将它直接保存到应用程序文件夹。

有什么想法吗?

感谢您的帮助。

【问题讨论】:

  • 这个 Storepath 是什么?这是一些预定义的功能还是我们必须给出这个,如果我们必须给出这个路径,那么如何?

标签: iphone camera


【解决方案1】:

您可以尝试在您的 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 方法中执行此操作:

UIImage *pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImagePNGRepresentation(pickedImage);

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"imageName.png"];

NSError * error = nil;
[imageData writeToFile:path options:NSDataWritingAtomic error:&error];

if (error != nil) {
    NSLog(@"Error: %@", error);
    return;
}

让我知道这是否适合你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 2013-07-22
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    相关资源
    最近更新 更多