zbar条形码扫描仅从图像无图像视图或相机胶卷

时间:2013-11-20 09:02:44

标签: 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条形码扫描。有人知道怎么做吗。我搜索了很多,但他们都使用图像捕获视图以及如何修改该视图。我需要的是我有一个图像[不在相机卷],我想通过zbar扫描它没有图像捕获视图或任何东西。请帮忙。除了zbar之外还有其他任何免费的库吗?

1 个答案:

答案 0 :(得分:1)

可以通过此

完成
 - (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