简体   繁体   English

自动启动FrontCamera并捕获图像

[英]automatically start FrontCamera and capture image

I want to make a camera application in which i want to start front camera automatically and capture image without user interaction. 我想制作一个相机应用程序,我想自动启动前置摄像头并在没有用户交互的情况下捕获图像。 thanks in advance. 提前致谢。

The UIImagePickerController is a higher level abstraction to the camera. UIImagePickerController是相机的更高级别的抽象。 Have a look at AVFoundation examples to see how to get to the camera more directly. 看看AVFoundation示例,了解如何更直接地访问相机。

The documentation for AVFoundation is here . AVFoundation的文档就在这里

To do it while still using the picker, have a look at. 要在仍然使用选择器的情况下执行此操作,请查看。 1317978 . 1317978 Look around for some examples using UIGetScreenImage() . 使用UIGetScreenImage()查看一些示例。 It used to be a private API but I think it is now allowed. 它曾经是一个私有API,但我认为它现在是允许的。

You might also want to look around at some examples concerning custom overlay, like this one . 您可能还想查看一些有关自定义叠加的示例,例如示例。

In addition to Robin's answer, add the following statements (before presentModalViewController:) to ensure that if the device has a front camera, that should be opened by default 除了Robin的回答之外,添加以下语句(在presentModalViewController :)之前,以确保如果设备有前置摄像头,则默认情况下应该打开

if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]){
 self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; //skipping this was crashing my app with some ** Assertion failure.
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}

Please note, if your app is compatible with devices running OS older than 4.0, you will have to put in conditional checks since cameraDevice property is available only in iOS 4.0 and later 请注意,如果您的应用程序与运行早于4.0的操作系统的设备兼容,则必须进行条件检查,因为cameraDevice属性仅在iOS 4.0及更高版本中可用

I dont know how much you know about objective-c or iphone development. 我不知道你对Objective-c或iphone开发了解多少。
so I will tell how to take photos in your iphone app. 所以我会告诉你如何在你的iPhone应用程序中拍照。
First you should get your self aquatinted with UIImagePickerController class 首先,您应该使用UIImagePickerController类进行自我绘制

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

here is some examples for the same from apple http://developer.apple.com/library/ios/samplecode/PhotoLocations/ 这里有一些来自苹果公司的例子http://developer.apple.com/library/ios/samplecode/PhotoLocations/

http://developer.apple.com/library/ios/samplecode/PrintPhoto/ http://developer.apple.com/library/ios/samplecode/PrintPhoto/

http://developer.apple.com/library/ios/samplecode/PhotoPicker/ http://developer.apple.com/library/ios/samplecode/PhotoPicker/

http://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/ http://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/

and next here is the code that will help you take the pics if you just place it in your .m file 接下来是代码,如果您只是将它放在.m文件中,它将帮助您拍摄照片

- (void)selectPhotos
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image;
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

now get started. 现在开始吧。

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

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