[英]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.