gpt4 book ai didi

ios - 如何强制 iOS 相机使用 AVFoundation 以编程方式拍照?

转载 作者:行者123 更新时间:2023-11-29 10:45:53 25 4
gpt4 key购买 nike

我需要 iOS 相机在没有用户输入的情况下拍照。我该怎么做呢?到目前为止,这是我的代码:

-(void)initCapture{
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] init];

AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];

NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey,
nil];


[newStillImageOutput setOutputSettings:outputSettings];


AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];

if ([newCaptureSession canAddInput:newVideoInput]) {
[newCaptureSession addInput:newVideoInput];
}
if ([newCaptureSession canAddOutput:newStillImageOutput]) {
[newCaptureSession addOutput:newStillImageOutput];
}
self.stillImageOutput = newStillImageOutput;
}

我还需要添加什么以及我从这里去哪里?我不想拍视频,只想拍一张静止图像。另外,之后如何将图像转换为 UIImage ?谢谢

最佳答案

https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureSession_Class/Reference/Reference.html

查看 AVCaptureSession 了解如何在没有用户输入的情况下拍照。您需要将摄像头的 AVCaptureDevice 添加到 session 中。

关于ios - 如何强制 iOS 相机使用 AVFoundation 以编程方式拍照?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22426293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com