ios - 仅从图像中无图像视图或相机胶卷扫描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条形码扫描。有人知道怎么做吗。我进行了很多搜索,但所有这些内容都使用图像捕获视图以及如何修改该视图。我需要的是我有一幅图像(不在相机胶卷中),并且我想通过zbar扫描图像,而没有图像捕获视图或其他任何东西。请帮忙。除了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

本文翻译自 https://stackoverflow.com/questions/20091444/

网站遵循 CC BY-SA 4.0 协议,转载或引用请注明出处。

标签 ios barcode-scanner zbar


相关文章:

c - 在C中使用带有ZBar的OpenCV的问题

ios - 如何返回像UITableview数据源这样的视图数(ZLSwipeableViewSwif)?

objective-c - IAP问题-response.products数组中没有产品

ios - 滑动以删除UITableView(iOS)中的整个部分

android - Android zbar中的相机黑屏

python - 通过zbar和Raspicam模组扫描QR码

objective-c - 应用程序终止时泄漏

android - NoClassDefFoundError:zxing的com.google.zxing.ResultMetadataType

ios - 我怎样才能获得适用于ios 5 iphone应用的UPC条码扫描器框架?

swift - 如何在Swift Project中导入Zbar Framework