Ios 如何使用AVFoundation framework使用iPhone摄像头拍照?
我需要iOS摄像头在没有用户输入的情况下拍照。我该怎么做呢?这是我目前的代码:Ios 如何使用AVFoundation framework使用iPhone摄像头拍照?,ios,objective-c,avfoundation,avcapturesession,ios-camera,Ios,Objective C,Avfoundation,Avcapturesession,Ios Camera,我需要iOS摄像头在没有用户输入的情况下拍照。我该怎么做呢?这是我目前的代码: -(void)initCapture{ AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] init]; AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictiona
-(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?谢谢根据,您应该能够执行以下操作:
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation: newStillImageOutput];
UIImage *image = [[UIImage alloc] initWithData:imageData];
这就是你的UIImage对象 是否有任何第三方框架用于从设备上拍照。这是另一个问题@karthikeyan;用一个新的问题来提问(并在这个新问题中解释为什么要避免使用AVFoundation框架)