2

我有一个应用程序,我在其中使用 ZBar 实现了二维码扫描。

现在我还在相机上实现了覆盖。

问题是虽然我做了一个覆盖,相机扫描整个屏幕的一部分。

我想在屏幕的某个部分进行扫描。

这是我的代码,

    reader = [ZBarReaderViewController new];
    isCameraStarted = YES;

    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    //Add flash Camera
    if(isTorchOn==NO)
        reader.cameraFlashMode=UIImagePickerControllerCameraFlashModeOff;
    else
        reader.cameraFlashMode=UIImagePickerControllerCameraFlashModeOn;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

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

    [scanner setSymbology:ZBAR_NONE config:ZBAR_CFG_ENABLE to:0];
    [scanner setSymbology:ZBAR_QRCODE
                   config:ZBAR_CFG_ENABLE
                       to:1];
    reader.cameraOverlayView = vw;
        reader.showsZBarControls=NO;
    [self presentViewController:reader animated:NO completion:nil];
    [reader release];

在方形中间框中打开相机

这是我想要的输出:

4

1 回答 1

1

尝试使用 ZBarReaderView,而不是使用 ZBarReaderViewController。下面的链接对我有用。

- (void)startScanning{
NSLog(@"Scanning..");
ZBarReaderView*reader = [ZBarReaderView new];
ZBarImageScanner * scanner = [ZBarImageScanner new];
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];
reader = [reader initWithImageScanner:scanner];
reader.readerDelegate = self;
reader.tracksSymbols = YES;
reader.frame = CGRectMake(10, 100, [self getWidth]- 20, [self getHeight] -200);
reader.torchMode = 0;
dispatch_async(dispatch_get_main_queue(), ^{[reader start];});

[self.container addSubview:reader];
}

-(void) readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet * )symbols fromImage :(UIImage *)image
{
for (ZBarSymbol *sym in symbols)
    {
    NSLog(@"Scanned data: %@", sym.data);
    break;
}
[readerView stop];
// action todo
}

希望能帮到你。

于 2014-02-08T22:39:09.077 回答