自动启动前置摄像头并拍摄照片

3

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


1
“自动”是什么意思?当您的应用程序启动时开始捕获吗? - Michael Petrotta
我尝试过这个,但它没有起作用。 - I_User
3个回答

1
除了 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及更高版本中可用。

1

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

AVFoundation文档在此处

如果仍然使用选择器进行操作,请查看1317978。浏览一些使用UIGetScreenImage()的示例。它曾经是一个私有API,但我认为现在已经允许使用了。

您还可以查看一些关于自定义覆盖层的示例,例如this one


http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html - my fat llama
我已经在上面发布了更多的选项。 - my fat llama

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];
}

现在开始吧。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接