我想在iOS7中扫描我的相册中的条形码或二维码图像。在iOS7中,我们可以使用相机扫描条形码图像,但我没有找到任何方法从UIImagePickerController中选择条形码图像并扫描它。在AVFoundation框架中有可用的方法吗?帮帮我..。
发布于 2014-05-06 15:40:23
我也有同样的问题,由于支持arm64的架构要求,大多数曾经完美运行的32位条形码SDK在7.1版本中都被破坏了。iOS受到了影响,ZXing完全脱离了Zbar平台,剩下的都是商业包。我尝试了其中一种叫做海牛的方法,它可以工作,但它从输出中截断了条形码的第一个字符。目前,你最好的选择是这些商业软件开发工具包在IOS 7.1上工作,或者回到7.0或6.1并使用Zbar。
由@Stark提出的AVfoundation解决方案可以很好地与相机捕捉配合使用(我对其进行了一些修改,以识别PDF417、AztecCodes和大约6个1D条形码),但是示例应用程序中的代码不能处理媒体库中的现有图像。我进行了密集的搜索,最近的选择是CoreImage检测,它对图像进行面部识别,不幸的是还没有条形码检测选项。
发布于 2014-04-29 13:26:38
有许多API可用于条形码扫描:
如果您只想使用AVfoundation框架,这里是教程的链接。http://www.appcoda.com/qr-code-ios-programming-tutorial/
下面是开始读取条形码的代码
 - (BOOL)startReading {
    NSError *error;
    AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
    if (!input) {
        NSLog(@"%@", [error localizedDescription]);
        return NO;
    }
    _captureSession = [[AVCaptureSession alloc] init];
    [_captureSession addInput:input];
    AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
    [_captureSession addOutput:captureMetadataOutput];
    dispatch_queue_t dispatchQueue;
    dispatchQueue = dispatch_queue_create("myQueue", NULL);
    [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
    [captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];
    _videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
    [_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [_videoPreviewLayer setFrame:_viewPreview.layer.bounds];
    [_viewPreview.layer addSublayer:_videoPreviewLayer];
    [_captureSession startRunning];
    return YES;
}并阻止它。
-(void)stopReading{
    [_captureSession stopRunning];
    _captureSession = nil;
    [_videoPreviewLayer removeFromSuperlayer];
}https://stackoverflow.com/questions/23343566
复制相似问题