ZBar scanning on ipad 4, setting scancrop

259 views Asked by At

I'm trying to get scanning work on iPad 4 using ZbarSDK. The following works fine on iPhones, but on iPad 4, it just doesn't read the barcode even though it auto-focuses. When i don't set cameraoverlayview/scanregion and scancrop, i do see it does read the barcode using the whole screen. But when i set the scan region that i want the user to use to scan the barcode in, it simply doesn't read.

-(void) initScanner
{

self.readerDelegate = self;
self.supportedOrientationsMask = ZBarOrientationMaskAll;
readerView = [readerView initWithImageScanner:scanner];

[self.scanner setSymbology: ZBAR_CODE39
                           config: ZBAR_CFG_ENABLE
                               to: 1];
[self.scanner setSymbology: ZBAR_CODE128
                    config: ZBAR_CFG_ENABLE
                        to: 1];
[self.scanner setSymbology: ZBAR_QRCODE
                           config: ZBAR_CFG_ENABLE
                               to: 0];
[self.scanner setSymbology: ZBAR_I25
                           config: ZBAR_CFG_ENABLE
                               to: 0];

[self.scanner setSymbology:ZBAR_EAN13 config:ZBAR_CFG_EMIT_CHECK to:0];
[self.scanner setSymbology:ZBAR_UPCA config:ZBAR_CFG_EMIT_CHECK to:0];

self.showsZBarControls=NO;
self.tracksSymbols =true;
self.readerView.zoom = 1.0;
self.readerView.torchMode=NO;

cameraOverlayView = [[UIView alloc] initWithFrame:self.view.frame];
UIImageView *overlayReticle = [[UIImageView alloc]          initWithFrame:CGRectMake(10,50,300,130)];
[overlayReticle setImage:[UIImage imageNamed:@"scannOverlay.png"]];
[cameraOverlayView addSubview:overlayReticle];

scanRegionView = [[UIView alloc] initWithFrame:CGRectMake(10,102,300,30)];
[cameraOverlayView addSubview:scanRegionView];

UIButton *torchButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
torchButton.frame = CGRectMake(cameraOverlayView.frame.origin.x, 200, 100, 30);
[torchButton setTitle:@"Torch" forState:UIControlStateNormal];
[torchButton addTarget:self action:@selector(toggleTorch:) forControlEvents:UIControlEventTouchUpInside];
torchButton.backgroundColor= [UIColor clearColor];
torchButton.tag = 99;
[cameraOverlayView addSubview:torchButton];

self.cameraOverlayView=cameraOverlayView;

self.scanCrop=[self getScanCropRectBasedOnTargetOverlayCropRect:scanRegionView.frame forOverlayViewSize:cameraOverlayView.frame.size];

}

and then I'm using this code from this link to calculate the scancrop value. Even though it works on iPhones, but on iPad 4 it doesn't. Is there anything else i need to consider, in case of iPads(like resolution), while calculating the scancrop?

Thanks.

1

There are 1 answers

0
user2993985 On

ok, i fixed this issue. I had to set the session preset for iPad to AVCaptureSessionPreset1920x1080.

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    self.readerView.session.sessionPreset = AVCaptureSessionPreset1920x1080;
}