【问题标题】:AVFoundation, AVCaptureMetadataOutput capturing screenshotAVFoundation, AVCaptureMetadataOutput 捕获截图
【发布时间】:2013-12-26 09:47:34
【问题描述】:

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

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

但我不知道如何使用我在此委托中的数据捕获扫描的 qrcode、条形码的图像。

【问题讨论】:

    标签: ios avfoundation avcapturesession avcapture capture-output


    【解决方案1】:

    我有captured imagescanning QRCode 是这样的:

    1)首先添加AVCaptureStillImageOutput's的属性

    @property (strong, nonatomic) AVCaptureStillImageOutput *stillImageOutput;
    

    2)初始化后在AVCaptureSession中添加会话预设

    [self.session setSessionPreset:AVCaptureSessionPreset640x480];
    

    3) 现在在AVCaptureSession 中添加AVCaptureStillImageOutput's 作为输出

    // 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

    【讨论】:

      猜你喜欢
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多