iOS 帮助:如何使用相机拍照并将其保存在 iPhone 上?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11590095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Help: How to use camera to take picture and save it on iPhone?
提问by Shahnawaz
I am new to iPhonedevelopment. I need to make an App where the user can take a picture and then its saved on the iPhone and also I have to use SQLiteDatabase to store the image and later display it.
我是iPhone开发新手。我需要制作一个应用程序,用户可以在其中拍照,然后将其保存在 iPhone 上,而且我必须使用SQLite数据库来存储图像并稍后显示它。
Can anyone help me with sample code and explanation of the procedure?
任何人都可以帮助我提供示例代码和程序说明吗?
EDIT: I made a button that uses an UIImageView to take picture, but I'm not sure if it works because I don't have an iPhone:
编辑:我制作了一个使用 UIImageView 拍照的按钮,但我不确定它是否有效,因为我没有 iPhone:
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
imagePicker = nil;
newMedia = YES;
}
The above code uses the front camera
上面的代码使用了前置摄像头
回答by Rahul Patel
you can use UIImagePickerControllerclass for take a picture..
you can use following methods for capture image and store it..
您可以使用UIImagePickerController类来拍照..您可以使用以下方法捕获图像并存储它..
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//put code for store image
}

