ipad zbar 实现 条码 二维码 读取

ipad zbar 实现 条码 二维码 读取,第1张

概述环境: I5、4G Win7旗舰版 64 Vm 8.0 Mac OS X Lion 10.7.2 VMware Image Xcode 4.3 IOS SDK 5.0 Ipad2 5.1.1 参考: We will develop a very simple app that presents a button the user can tap to invoke the barcode read 环境: I5、4G Win7旗舰版 64 Vm 8.0 Mac OS X lion 10.7.2 VMware Image Xcode 4.3 IOS SDK 5.0 Ipad2 5.1.1 参考: We will develop a very simple app that presents a button the user can tap to invoke the barcode reader and then displays the results. Interface Builder will be used to create the interface. The completed project is also available with the distributed SDK under Examples/ReaderSample. 1.2.1. Create the App Open Xcode; you must have version 3.2.3 or later. Create a new project using the “VIEw-based Application” template. name the project “ReaderSample”. Save it wherever you like. Open ReaderSampleVIEwController.xib Drag a Round Rect button onto the vIEw and Title it “Scan”. Customize the placement and appearance as you like. Drag an Image VIEw onto the vIEw. Size it to fill about half of the remaining space. Change the vIEw mode to Aspect Fit. Drag a Text VIEw onto the vIEw and size it to fill the remaining space. Change the default text to “No barcode scanned” or something. De-select “Editable” Add connections to the interface elements in the code; open ReaderSampleVIEwController.h and change the interface to: @interface ReaderSampleVIEwController : UIVIEwController {     UIImageVIEw *resultimage;     UITextVIEw *resultText; } @property (nonatomic,retain) IBOutlet UIImageVIEw *resultimage; @property (nonatomic,retain) IBOutlet UITextVIEw *resultText; - (IBAction) scanbuttonTapped; @end Now we can finish the interface connections - open ReaderSampleVIEwController.xib and make these connections: Connect ReaderSampleVIEwController resultimage outlet to the ImageVIEw. Connect ReaderSampleVIEwController resultText outlet to the TextVIEw. Connect ReaderSampleVIEwController scanbuttonTapped action to the RoundedRectbutton(Scan) event touchUpInsIDe. Consult the Xcode documentation if you need help making these connections. Make sure you save the XIB once they are finished. Finish the implementation in ReaderSampleVIEwController.m: @synthesize resultimage,resultText; - (IBAction) scanbuttonTapped {     NSLog(@"TBD: scan barcode here..."); } - (voID) dealloc {     self.resultimage = nil;     self.resultText = nil;     [super dealloc]; } - (BOol) shouldautorotatetoInterfaceOrIEntation: (UIInterfaceOrIEntation) interfaceOrIEntation {     return(YES); } This stub for scanbuttonTapped is temporary,we’ll fix it in a minute... Although it doesn’t do much yet,you should Now have a working skeleton app that you can build and run. 1.2.2. Integrate the Reader Now for the exciting part - let’s add a barcode reader! If you have not done so already,download the latest SDK from http://zbar.sourceforge.net/iphone Double-click the disk image,ZbarSDK-1.2.dmg in the Finder to open it. Drag the ZbarSDK folder into your Xcode project. Make sure that the “copy Items into destination group’s folder” checkBox is checked. Open the target build settings and find link Binary With librarIEs. Click the + and add each of these (NB hold down command for multiple selection): AVFoundation.framework CoreMedia.framework CoreVIDeo.framework QuartzCore.framework libiconv.dylib Warning link order may be important for some versions of Xcode; the librarIEs referenced above should be Listed before libzbar.a in the link order. import the SDK header. You will usually want to prefix it,so add it to ReaderSample-prefix.pch: // ADD: import barcode reader APIs #import "ZbarSDK.h" Declare support for the delegate protocol in ReaderSampleVIEwController.h: @interface ReaderSampleVIEwController : UIVIEwController     // ADD: delegate protocol     < ZbarReaderDelegate > { ... Re-implement scanbuttonTapped to present a barcode reader when the user taps the Scan button. In ReaderSampleVIEwController.m: - (IBAction) scanbuttonTapped {     // 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]; } Finally,implement the delegate method to do something useful with the results. Still in ReaderSampleVIEwController.m: - (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]; } And that’s it! 1.2.3. Testing Save everything (don’t forget to save MyAppVIEwController.xib). Build and Run the project. Tap the Scan button. aim at barcode. Enjoy the sweet fruits of your minimal labor 1.2.4. Where to go from here You can learn more about using the reader APIs to scan barcodes from Scanning From the Camera Feed or Scanning a User-Selected Image. Use the API Reference to find details about a particular interface. 1.2.5. Troubleshooting We take great care to ensure this tutorial is working as described. However,if you do have a problem Make sure you followed the instructions exactly - every detail is important. Start from scratch with a new project and follow the instructions exactly. Try the ReaderSample distributed with the SDK and compare your work with that. If you are unable to get things working,you may post your frustrations in the project iPhone Developers Forum. Please be very specific about your problem,post the complete text of any errors,etc. 总结

以上是内存溢出为你收集整理的ipad zbar 实现 条码 二维码 读取全部内容,希望文章能够帮你解决ipad zbar 实现 条码 二维码 读取所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1090229.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存