xcode 如何从 iphone 中的本机应用程序打开相机?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1424905/
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
how to open camera from native application in iphone?
提问by Rahul Vyas
I want to write a app in which I open the camera take a picture and then edit the picture.I want to apply some cool effects on image as well.something like image editing...does some one knows a good or I say best approach to achieve this?
我想编写一个应用程序,在其中我打开相机拍照然后编辑图片。我也想在图像上应用一些很酷的效果。像图像编辑之类的东西......有人知道好还是我说最好实现这一目标的方法?
I want to know that is open-gl necessary to create an aap like image editing ?
我想知道创建像图像编辑这样的 aap 需要 open-gl 吗?
回答by PeyloW
This is truly easy. Your code will be in a subclass of UIViewController, let this class conform to the UIImagePickerControllerDelegateprotocol, this allows your controller to receive images from the camera and/or users library.
这真的很容易。您的代码将在 的子类中UIViewController,让这个类符合UIImagePickerControllerDelegate协议,这允许您的控制器从相机和/或用户库接收图像。
Now you have to create and display a UIImagePickerController, this view controller can be used for both selecting images from the users library, and taking images/video with the camera. Implement something like this:
现在您必须创建并显示一个UIImagePickerController,该视图控制器可用于从用户库中选择图像,以及使用相机拍摄图像/视频。实现这样的事情:
-(IBAction)takePictureWithCamera {
UIImagePickerController* controller = [[UIImagePickerController alloc] init];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
[controller release];
}
This will display the image picker, see documentation for UIImagePickerControllerfor how to customize further if needed.
这将显示图像选择器,UIImagePickerController有关如何在需要时进一步自定义的信息,请参阅文档。
Next you need to receive the image the user picks, or takes with the camera. This is done by implementing the method imagePickerController:didFinishPickingMediaWithInfo:from the UIImagePickerControllerDelegateprotocol.
接下来,您需要接收用户选择或使用相机拍摄的图像。这是通过实现协议中的方法imagePickerController:didFinishPickingMediaWithInfo:来完成的UIImagePickerControllerDelegate。
-(void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingMediaWithInfo:(NSDictionary*)info {
UIImage* image = [info objectForKey: UIImagePickerControllerOriginalImage];
// Do stuff to image.
}
And that is it.
就是这样。
回答by Tim
Take a look at the UIImagePickerControllerclass. It's a view controller that you can present modally, and it lets you "pick" an image from the camera using the iPhone's native interface for taking photos.
看看UIImagePickerController类。它是一个可以模态呈现的视图控制器,它让您可以使用 iPhone 的本机界面从相机中“挑选”图像以进行拍照。

