【问题标题】:How to capture picture without user interaction in iOS?在 iOS 中如何在没有用户交互的情况下捕获图片?
【发布时间】:2023-03-20 04:00:01
【问题描述】:

我正在为 iPhone 开发一款移动追踪应用程序。我想在没有用户交互的情况下捕获用户的图片。我在 Google 上搜索过,但发现两个链接不符合我的要求。我发现我们可以通过使用 AVCam 和 AVFoundation 来做到这一点。是否有与此相关的示例代码?有示例代码吗?

【问题讨论】:

标签: iphone ios objective-c avfoundation


【解决方案1】:

-takePicture 应该真正做到这一点。您必须为相机控件提供自定义UI,否则(对我而言)它不起作用。查看 Xcode 中的开发人员文档并搜索 takePicture。方法描述有你需要的一切。

以下为您提供简单的逻辑:

- (IBAction) showCameraUI
{
    UIImagePickerController *picker;
    // create and display picker

   self.imagePicker = imagePicker;
   [NSTimer scheduledTimerWithTimeInterval:4.0
                             target:self
                           selector: @selector(targetMethod)
                           userInfo:nil
                            repeats:YES];
}

- (void)targetMethod
{
    [self.picker takePicture];
    // ...
}

其他选项是

我发现...

AVCaptureVideoDataOutputSampleBufferDelegate

自动拍照。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer   
   fromConnection:(AVCaptureConnection *)connection 

Checke official documentthis link with source of code.

很简单,谢谢:)

【讨论】:

  • 但是我应该在哪里关闭视图
  • 当我使用它时,它会捕获多张图像
  • 使用这个方法 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-21
  • 2016-10-07
  • 1970-01-01
  • 2014-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多