Fully Objective-C Port Of Open Source Barcode Scanner/Creator ZXing

I’ve mentioned an open source app called Barcode scanner that provides an example showing how to use the C++ port of ZXing on the iOS platform.

Recently I received a tip about a Objective-C port of Zxing called ZXingObjc.

ZXingObjc provides a full port of ZXing to Objective-C so all your barcode scanning, and barcode creation can be done completely with Objective-C without the hassle of linking up to and using the C++ ZXing port.

Here’s an example from the readme shows decoding done using Objective-C:

CGImageRef imageToDecode;  // Given a CGImage in which we are looking for barcodes

ZXLuminanceSource* source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
ZXBinaryBitmap* bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];

NSError* error = nil;

// There are a number of hints we can give to the reader, including
// possible formats, allowed lengths, and the string encoding.
ZXDecodeHints* hints = [ZXDecodeHints hints];

ZXMultiFormatReader* reader = [ZXMultiFormatReader reader];
ZXResult* result = [reader decode:bitmap
                            hints:hints
                            error:&error];
if (result) {
  // The coded result as a string. The raw data can be accessed with
  // result.rawBytes and result.length.
  NSString* contents = result.text;

  // The barcode format, such as a QR code or UPC-A
  ZXBarcodeFormat format = result.barcodeFormat;
} else {
  // Use error to determine why we didn’t get a result, such as a barcode
  // not being found, an invalid checksum, or a format inconsistency.
}

You can find ZXingObjc on Github here.

Examples are included for creating and scanning bar codes and QR codes.

Thanks to Chris for the submission.

FacebookTwitterDiggStumbleUponGoogle Plus

Original article: Fully Objective-C Port Of Open Source Barcode Scanner/Creator ZXing

©2013 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *