3

我正在使用AVCaptureMetadataOutput以使用 iOS QRCode,条形码扫描功能。这很好用,我得到了通过AVCaptureMetadataOutput委托方法扫描的结果

-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{

但我不知道如何使用我在这个代表中拥有的数据来捕获扫描的 qrcode、条形码的图像。

4

1 回答 1

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);
}];

参考使用CodeScanViewController

就是这样@Enjoy

于 2015-07-07T11:18:11.610 回答