Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set scan frame in zbar SDK?

Tags:

iphone

camera

I an using Zbar SDK and want to scan QRcode and barcode in my define frame but it is scanning in any part of screen not in my defined frame so where i am doing mistake? I want to do scan like this in my defined frame.
http://www.visionsmarts.com/products/VSBarcodeReader/VSBarcodeReader.html

here is my code.

-(void)displayMe{


ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;

reader.showsZBarControls=NO;

//////////////black area/////////////////////////

UIImage *image1 = [UIImage imageNamed:@"blackscreen.png"];
UIImageView *imageLogo1 = [[UIImageView alloc] initWithImage:image1];
imageLogo1.frame = CGRectMake(0, 0, 320, 480);

cancelLabel =[[UILabel alloc]initWithFrame:CGRectMake(0,420, 320, 60)];
cancelLabel.backgroundColor = [UIColor blackColor];


UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(100,420, 100, 60)];
[btn setTitle:@"Cancel" forState:UIControlStateNormal]; 
btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
btn.backgroundColor=[UIColor blackColor];
[btn addTarget:self action:@selector(back) 
forControlEvents:UIControlEventTouchUpInside];


[cancelLabel bringSubviewToFront:btn];
[imageLogo1 addSubview:cancelLabel];
[imageLogo1 setUserInteractionEnabled:YES];
[imageLogo1 addSubview:btn];
//reader.cameraOverlayView = btn;


///////////////line/////////////////////////////
UIImage *image = [UIImage imageNamed:@"[email protected]"];
UIImageView *imageLogo = [[UIImageView alloc] initWithImage:image];
imageLogo.frame = CGRectMake(40, 240, 230, 10);
[imageLogo1 addSubview:imageLogo];

///////////////Configure reader///////////////////////////////
reader.cameraOverlayView = imageLogo1;

//reader.cameraOverlayView.frame=CGRectMake(40, 240, 230, 30);

//imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);


//imageLogo.center = CGRectMake(320/2, 460/2, image.size.width, image.size.height);

ZBarImageScanner *scanner = reader.scanner;

[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 1];


ZBarCaptureReader *cap=[[ZBarCaptureReader alloc]init];

//cap.scanCrop=CGRectMake(300, 400, 230, 200);

cap.scanCrop=CGRectMake(100, 160, 50,60);
//cap.cameraOverlayView.frame=CGRectMake(40, 240, 230, 30);


[self presentModalViewController: reader
                        animated: YES];
[reader release];
like image 226
Furqi Avatar asked Nov 03 '11 07:11

Furqi


2 Answers

Make a UIVIew (e.g. scanView) object and make it as your customize area. Where u want to get scan area there should be transparent area or In image transparent cut.

use this

reader.cameraOverlayView = scanView;

Also disable to all mode except Portrait mode.

reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);

Full e.g. code

In MyScanCode.h file

{ZBarReaderViewController *reader;}
@property (nonatomic, strong) IBOutlet UIView *scanView;

In MyScanCode.m file

- (void) readCode{
    reader = [ZBarReaderViewController new];

    reader.readerDelegate =  self;
    reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);

    #if !(TARGET_IPHONE_SIMULATOR)    
        reader.cameraOverlayView = scanView;
        reader.showsZBarControls = NO;
    #endif

    reader.wantsFullScreenLayout = NO;
    ZBarImageScanner *scanner = reader.scanner;

    [scanner setSymbology:ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
    [self presentModalViewController:reader animated:NO];

}
like image 159
dayitv89 Avatar answered Oct 26 '22 01:10

dayitv89


Instead of using ZBarReaderViewController, try using ZBarReaderView. This worked for me and saved my lot of time. Hope it helps you.

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(20, 126-88, 283, 347);
reader.torchMode = 0;
dispatch_async(dispatch_get_main_queue(), ^{[reader start];});

[self.view addSubview:reader];
like image 23
shripad20 Avatar answered Oct 26 '22 01:10

shripad20