Huy Tran
Huy Tran

Reputation: 4431

Use camera scan QRCode or BarCode in ObjectiveC

I want to build an app to scan QRCode and Barcode. I want to use camera scan image contains the code (QRCode or BarCode) but not take photo. Now I have no idea to do it.
Anyone, give some references, please!

Upvotes: 2

Views: 6334

Answers (3)

smparkes
smparkes

Reputation: 14053

The two most active projects are ZBar and ZXing.

You didn't mention if you were targeting iOS or OS X. I don't believe ZBar suports OS X. ZXing does. I believe ZBar has better support for 1D codes than the C++-based ports of ZXing.

(FWIW, I'm an active contributor to the C++/OS X/iOS port of ZXing.)

Upvotes: 1

Rinju  Jain
Rinju Jain

Reputation: 1694

Download the ZBarSDK and import it in pch file then use this code

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

Upvotes: 1

jussi
jussi

Reputation: 2216

You should look at: http://zbar.sourceforge.net/

Upvotes: 5

Related Questions