[英]automatically start FrontCamera and capture image
我想制作一个相机应用程序,我想自动启动前置摄像头并在没有用户交互的情况下捕获图像。 提前致谢。
除了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/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.