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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:21:27  来源:igfitidea点击:

iOS Help: How to use camera to take picture and save it on iPhone?

iphoneobjective-ciosios5ios4

提问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
 }                

回答by The iOSDev

You can use the examples available on apple's developer library

您可以使用苹果开发者库中提供的示例

see these examples

看这些例子

and many more reference material is available too.

还有更多的参考资料可供使用。

Happy Coding :)

快乐编码:)