gpt4 book ai didi

iphone - zbar SDK中如何设置扫描框?

转载 作者:行者123 更新时间:2023-12-03 18:57:30 25 4
gpt4 key购买 nike

我正在使用 Zbar SDK,想要扫描我的定义框架中的 QRcode 和条形码,但它正在扫描屏幕的任何部分,而不是在我定义的框架中,所以我在哪里做错了? 我想在我定义的框架中进行这样的扫描。
http://www.visionsmarts.com/products/VSBarcodeReader/VSBarcodeReader.html

这是我的代码。

-(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:@"ScannerKitLaser@2x.png"];
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];

最佳答案

创建一个 UIVIew(例如 scanView)对象并将其作为您的自定义区域。在您想要获得扫描区域的地方应该有透明区域或在图像透明剪切中。

用这个

reader.cameraOverlayView = scanView;

同时禁用除纵向模式之外的所有模式。

reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);

完整例如代码

在 MyScanCode.h 文件中

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

在 MyScanCode.m 文件中

- (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];

}

关于iphone - zbar SDK中如何设置扫描框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7991446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com