我正在尝试找出如何使用iPhone相机拍摄并直接将图像保存到应用程序的文档文件夹中,如果可能的话不要保存到相机胶卷。
我的应用程序可以显示相机,并且我可以将图像保存到相机胶卷中,但我想直接保存到应用程序的文档文件夹中。
有什么建议吗?
感谢您的帮助。
你可以尝试在你的- (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;
}