我正在使用AVCaptureMetadataOutput
来使用iOS QRCode,条形码扫描功能。这很好用,我得到了扫描AVCaptureMetadataOutput
委托方法
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
但我不知道如何捕获扫描的qrcode图像,条形码和我在此代表中的数据。
答案 0 :(得分:1)
我有captured image
而scanning QRCode
喜欢这样:
1)首先添加AVCaptureStillImageOutput's
@property (strong, nonatomic) AVCaptureStillImageOutput *stillImageOutput;
2)在初始化后在AVCaptureSession
添加会话预设
[self.session setSessionPreset:AVCaptureSessionPreset640x480];
3)现在在AVCaptureStillImageOutput's
AVCaptureSession
作为输出
// Prepare an output for snapshotting
self.stillImageOutput = [AVCaptureStillImageOutput new];
[self.session addOutput:self.stillImageOutput];
self.stillImageOutput.outputSettings = @{AVVideoCodecKey: AVVideoCodecJPEG};
4)在代理方法captureOutput:didOutputMetadataObjects:fromConnection:connection
中添加以下代码以捕获扫描图像
__block UIImage *scannedImg = nil;
// Take an image of the face and pass to CoreImage for detection
AVCaptureConnection *stillConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:stillConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if(error) {
NSLog(@"There was a problem");
return;
}
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
scannedImg = [UIImage imageWithData:jpegData];
NSLog(@"scannedImg : %@",scannedImg);
}];
多数民众赞成@Enjoy