zoukankan      html  css  js  c++  java
  • iOS二维码,条形码扫描问题

    1.公司做一个二维码条形码扫描的项目,遇到二维码扫描很好识别,条形码扫描有点慢

    解决办法:device放大焦距(完美解决)

     

     //获取摄像设备

        AVCaptureDevice * device = [AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeVideo];

        //创建输入流

        AVCaptureDeviceInput * input = [AVCaptureDeviceInputdeviceInputWithDevice:device error:nil];

        //创建输出流

        AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutputalloc]init];

        //设置代理在主线程里刷新

        [output setMetadataObjectsDelegate:selfqueue:dispatch_get_main_queue()];

        output.rectOfInterest = scanCrop;

    //    [ output setRectOfInterest : CGRectMake (( 124 )/ ScreenHEI ,(( ScreenWHD - 220 )/ 2 )/ ScreenWHD , 220 / ScreenHEI , 220 / ScreenWHD )];

        //初始化链接对象

        session = [[AVCaptureSessionalloc]init];

        //高质量采集率

        [sessionsetSessionPreset:AVCaptureSessionPresetHigh];

        if (input) {

            [sessionaddInput:input];

        }

        if (output) {

            [sessionaddOutput:output];

            //设置扫码支持的编码格式(如下设置条形码和二维码兼容)

            NSMutableArray *a = [[NSMutableArrayalloc] init];

            if ([output.availableMetadataObjectTypescontainsObject:AVMetadataObjectTypeQRCode]) {

                [a addObject:AVMetadataObjectTypeQRCode];

            }

            if ([output.availableMetadataObjectTypescontainsObject:AVMetadataObjectTypeEAN13Code]) {

                [a addObject:AVMetadataObjectTypeEAN13Code];

            }

            if ([output.availableMetadataObjectTypescontainsObject:AVMetadataObjectTypeEAN8Code]) {

                [a addObject:AVMetadataObjectTypeEAN8Code];

            }

            if ([output.availableMetadataObjectTypescontainsObject:AVMetadataObjectTypeCode128Code]) {

                [a addObject:AVMetadataObjectTypeCode128Code];

            }

            output.metadataObjectTypes=a;

        }

        /*

         [ _output setRectOfInterest : CGRectMake (( 124 )/ ScreenHigh ,(( ScreenWidth - 220 )/ 2 )/ ScreenWidth , 220 / ScreenHigh , 220 / ScreenWidth )];

         */

        AVCaptureVideoPreviewLayer * layer = [AVCaptureVideoPreviewLayerlayerWithSession:session];

        layer.videoGravity=AVLayerVideoGravityResizeAspectFill;

        layer.frame = CGRectMake(0, 0, [UIScreenmainScreen].bounds.size.width, self.ScanReadView.frame.size.height);

        [self.ScanReadView.layerinsertSublayer:layer atIndex:0];

        

        [selfsetOverlayPickerView:self.ScanReadView];

        //放大焦距

        NSError *error = nil;

        [device lockForConfiguration:&error];

        

        if (device.activeFormat.videoMaxZoomFactor > 2) {

            device.videoZoomFactor = 2;

        }else{

            device.videoZoomFactor = device.activeFormat.videoMaxZoomFactor;

        }

        

        [device unlockForConfiguration];

        //开始捕获

        [sessionstartRunning];

     

  • 相关阅读:
    OI回忆录——一个过气OIer的制杖历程
    博客园美化手记——CSS javascript html
    ProjectEuler && Rosecode && Mathmash做题记录
    算法竞赛推荐
    2020智算之道复赛E 树数数
    牛客编程巅峰赛S1第9场
    c++小学期大作业攻略(五)基于QSS的样式美化
    c++小学期大作业攻略(四)任务系统+站内信
    c++小学期大作业攻略(三)用户系统
    c++小学期大作业攻略(零)建议+代码结构(持续更新)
  • 原文地址:https://www.cnblogs.com/coolcold/p/5775276.html
Copyright © 2011-2022 走看看