简体   繁体   English

将iPhone相机中的图像直接保存到文档文件夹而不是相机胶卷?

[英]Save image from iPhone camera directly to documents folder and not to camera roll?

I am trying to figure out how to take a image with the iPhone camera and save it directly to the apps document folder, and if possible not in the camera roll. 我试图弄清楚如何使用iPhone相机拍摄图像并将其直接保存到应用程序文档文件夹中,如果可能的话,不要在相机胶卷中保存。

I have my app showing the camera, and I can save the image to the camera roll, but I want to save it directly to the apps document folder. 我有我的应用程序显示相机,我可以将图像保存到相机胶卷,但我想将其直接保存到apps文档文件夹。

Any idea ? 任何的想法 ?

Thanks for the help. 谢谢您的帮助。

You can try doing this in your - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info method: 你可以试试这个- (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;
}

Let me know if that works for you. 如果这对您有用,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM