【发布时间】:2026-02-24 02:40:01
【问题描述】:
我需要 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 ?谢谢
【问题讨论】:
标签: ios objective-c ios-camera