我想构建一个应用程序来扫描 QRCode 和 Barcode。我想使用相机扫描图像包含代码(QRCode 或 BarCode)但不拍照。现在我不知道该怎么做。
哪位大神,给个参考吧!
问问题
6146 次
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 回答