gpt4 book ai didi

iphone - ios应用程序中的QR码扫描

转载 作者:IT王子 更新时间:2023-10-29 07:56:26 26 4
gpt4 key购买 nike

我需要在应用程序中集成 QR 码阅读器并找到一个 tutorial

我从这个link下载了Z-bar sdk .

这是我所做的。

在QRscannerViewController.m中

-(IBAction)StartScan:(id) sender
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;

reader.readerView.torchMode = 0;

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

// present and release the controller
[self presentModalViewController: reader
animated: YES];
[reader release];

resultTextView.hidden=NO;
}

- (void) readerControllerDidFailToRead: (ZBarReaderController*) reader
withRetry: (BOOL) retry{
NSLog(@"the image picker failing to read");

}

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{


NSLog(@"the image picker is calling successfully %@",info);
// ADD: get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
NSString *hiddenData;
for(symbol in results)
hiddenData=[NSString stringWithString:symbol.data];
NSLog(@"the symbols is the following %@",symbol.data);
// EXAMPLE: just grab the first barcode
// break;

// EXAMPLE: do something useful with the barcode data
//resultText.text = symbol.data;
resultTextView.text=symbol.data;


NSLog(@"BARCODE= %@",symbol.data);

NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
[storeData setObject:hiddenData forKey:@"CONSUMERID"];
NSLog(@"SYMBOL : %@",hiddenData);
resultTextView.text=hiddenData;
[reader dismissModalViewControllerAnimated: NO];

}

添加了所有需要的框架,因此没有referenced from错误。

当我点击扫描按钮时,ZBarReaderViewController 显示正常,我按住 alt 键并左键单击鼠标打开模拟器的照片库,一切正常。

问题是什么,

  1. QR 图像未被扫描,即 imagePickerController:
    (UIImagePickerController*) 读者 didFinishPickingMediaWithInfo
    函数未被调用。
  2. QR 图片看起来比原始尺寸大。

enter image description here

如何解决?

为什么扫描不到图像?

最佳答案

随着 iOS7 的发布,您不再需要使用外部框架或库。 带有 AVFoundation 的 iOS 生态系统现在完全支持扫描从 QR over EAN 到 UPC 的几乎所有代码。

看看Tech NoteAVFoundation programming guide . AVMetadataObjectTypeQRCode是你的 friend 。

这是一个很好的教程,它一步一步地展示了它: iPhone QR code scan library iOS7

只是一个关于如何设置它的小例子:

#pragma mark -
#pragma mark AVFoundationScanSetup

- (void) setupScanner
{
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];

self.session = [[AVCaptureSession alloc] init];

self.output = [[AVCaptureMetadataOutput alloc] init];
[self.session addOutput:self.output];
[self.session addInput:self.input];

[self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];

self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.preview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

AVCaptureConnection *con = self.preview.connection;

con.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;

[self.view.layer insertSublayer:self.preview atIndex:0];

[self.session startRunning];

}

关于iphone - ios应用程序中的QR码扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16166646/

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