【问题标题】:Capturing image without user interaction在没有用户交互的情况下捕获图像
【发布时间】:2013-05-20 08:43:38
【问题描述】:

我想在 iOS 中使用前置摄像头在没有任何用户交互的情况下拍摄照片。谁能告诉我如何做到这一点?

我在UIImagePickerController 类中使用了takePicture 函数,但它不起作用,因为委托方法(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 永远不会被调用:

-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//Use camera if device has one otherwise use photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

[imagePicker setDelegate:self];

//Show image picker
     [imagePicker takePicture];
}

谁能告诉我正确的方法吗?

【问题讨论】:

    标签: ios objective-c xcode uiimagepickercontroller


    【解决方案1】:

    需要添加以下代码

    //Getting image from front camera
    imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    
    [self imagePicker animated:YES completion:nil];
    

    【讨论】:

    • 不,根本解决不了 :) 1 行是多余的,2 行是无效的 objc
    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    相关资源
    最近更新 更多