ios - 仅从图像扫描 zbar 条形码,无 ImageView 或相机胶卷

标签 ios barcode-scanner zbar

嗨,如果我用这个制作图像捕获屏幕

-(void)initializecam{
     AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;

CALayer *viewLayer = self.vImagePreview.layer;
NSLog(@"viewLayer = %@", viewLayer);

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
    // Handle the error appropriately.
    NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];
_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];

[session addOutput:_stillImageOutput];
[session startRunning];
}

所以现在我想用zbar条码扫描。有人知道怎么做吗。我搜索了很多,但所有这些都是他们使用图像捕获 View 以及如何修改该 View 。我所需要的只是我有一张图像[不在相机胶卷中],我想通过 zbar 扫描它,没有图像捕获 View 或任何东西。请帮忙。除了 zbar 之外,还有其他免费图书馆可以做到这一点吗?

最佳答案

可以这样做

 - (void)scan {
// ADD: present a barcode reader that scans from the camera feed

    ZBarReaderController *reader = [ZBarReaderController new];
    reader.readerDelegate = self;
    ZBarImageScanner *scanner = reader.scanner;

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    CGImageRef imgCG = self.imgCameraView.image.CGImage;

id<NSFastEnumeration> results = [reader scanImage:imgCG];
ZBarSymbol *symbol = nil;
for(ZBarSymbol *symbolF in results){
    // EXAMPLE: just grab the first barcode
    symbol=symbolF;
    break;
}

if([symbol.data length]>0){
    NSLog(@"Bar Code ID = %@",symbol.data);
    self.ticketCode=symbol.data;

    [self verifybarCode];
    self.vImagePreview.hidden=FALSE;
}
else
{
[[iToast makeText:AMLocalizedString(@"Image Is Not Properly Scanned\nTry Again", nil)] show];
self.vImagePreview.hidden=FALSE;
}

}

之前我使用的是 ZBarReaderViewController

关于ios - 仅从图像扫描 zbar 条形码,无 ImageView 或相机胶卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20091444/

相关文章:

android - 通过相机扫描图像和从相机捕获图像之间有什么区别吗?

iphone - 条码 SDK 支持 iPhone 的一维码、二维码、数据矩阵等

iphone - 在屏幕的特定部分打开 zbar 扫描仪

ios - 从 ARKit 获取特征点

ios - Iphone 与服务器交互以最小化新规则的负载。

ios - 尝试保存数组时 CoreData 出错。 'Cannot convert value of type ' String' 到预期参数类型 'NSManagedObject' '

barcode - 使用条码扫描器作为键盘楔子是否意味着您无法确认收到扫描件?

ios - UINavigationController 包含、iOS7 和状态栏。漏洞?

安卓 : converting RGB888 to Y800

ios - 无法识别的选择器发送到类 0x865c6c