簡體   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