繁体   English   中英

自动启动FrontCamera并捕获图像

[英]automatically start FrontCamera and capture image

我想制作一个相机应用程序,我想自动启动前置摄像头并在没有用户交互的情况下捕获图像。 提前致谢。

UIImagePickerController是相机的更高级别的抽象。 看看AVFoundation示例,了解如何更直接地访问相机。

AVFoundation的文档就在这里

要在仍然使用选择器的情况下执行此操作,请查看。 1317978 使用UIGetScreenImage()查看一些示例。 它曾经是一个私有API,但我认为它现在是允许的。

您可能还想查看一些有关自定义叠加的示例,例如示例。

除了Robin的回答之外,添加以下语句(在presentModalViewController :)之前,以确保如果设备有前置摄像头,则默认情况下应该打开

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

请注意,如果您的应用程序与运行早于4.0的操作系统的设备兼容,则必须进行条件检查,因为cameraDevice属性仅在iOS 4.0及更高版本中可用

我不知道你对Objective-c或iphone开发了解多少。
所以我会告诉你如何在你的iPhone应用程序中拍照。
首先,您应该使用UIImagePickerController类进行自我绘制

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

这里有一些来自苹果公司的例子http://developer.apple.com/library/ios/samplecode/PhotoLocations/

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

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

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

接下来是代码,如果您只是将它放在.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];
}

现在开始吧。

暂无
暂无

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

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