2

我想构建一个应用程序来扫描 QRCode 和 Barcode。我想使用相机扫描图像包含代码(QRCode 或 BarCode)但不拍照。现在我不知道该怎么做。
哪位大神,给个参考吧!

4

3 回答 3

5

你应该看看:http: //zbar.sourceforge.net/

于 2012-07-25T08:40:52.747 回答
1

下载 ZBarSDK 并将其导入 pch 文件,然后使用此代码

// BarCodeView.h
@interface BarCodeView : UIViewController  < ZBarReaderDelegate > {
UIImageView *resultImage;
UITextView *resultText;
  }
@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextView *resultText;
- (IBAction) scanButtonTapped;

    // BarCodeView.m
  @synthesize resultImage, resultText;
   - (IBAction) scanButtonTapped
 {
NSLog(@"TBD: scan barcode here...");
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

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];
  }
 - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
  {
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
    // EXAMPLE: just grab the first barcode
    break;

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

// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];

// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
 }
于 2012-07-25T08:54:13.673 回答
1

最活跃的两个项目是ZBarZXing

你没有提到你的目标是 iOS 还是 OS X。我不相信 ZBar 支持 OS X。ZXing 支持。我相信 ZBar 对一维代码的支持比 ZXing 基于 C++ 的端口更好。

(FWIW,我是 ZXing 的 C++/OS X/iOS 端口的积极贡献者。)

于 2012-07-26T03:12:09.160 回答