2

Is there a framework or other sample code for doing barcode recognition (create and scan) on cocoa [OS X]?

Lion
  • 872
  • 1
  • 17
  • 43

4 Answers4

2

You have to use a third-party framework for that.

For example, you can use:

  • ZXing. Note that the 1D code is not stabilized, so you probably will have to dig into the code.
  • ZBar. Seems to be a very capable library.

A simple Google search or StackOverflow search can help you too.

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81
  • ZBar is for iOS right. I am looking for cocoa. Any sample application using ZXing in cocoa. – Lion Jun 16 '12 at 11:52
  • 3
    I'm hoping to add a clean and simple sample app for os x as well as new clean project files for zxing Real Soon Now. There are two sample apps (see the README in the objc directory) but they're far from ideal. – smparkes Jun 16 '12 at 16:32
  • There is a Zbar Wrapper for OS X as well. Check it out here: https://github.com/srgtuszy/ZbarCocoa – Andreas Zöllner Oct 01 '15 at 08:30
  • None of these frameworks really work with the built-in camera of a standard 5K iMac – Ely Nov 27 '17 at 10:12
1

This here creates 2D barcodes for both mac and iphone: Cocoa Barcodes

IluTov
  • 6,807
  • 6
  • 41
  • 103
  • I think this library is incomplete I tried to implement but got bugs. Is there any sample application using Cocoa Barcodes. – Lion Jun 18 '12 at 06:07
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/29851979) – camille Sep 17 '21 at 17:14
  • @camille How do you give a precise answer to a broad question? – IluTov Sep 18 '21 at 16:51
  • Maybe you just don't. Obviously some of the criteria for questions have changed since this was posted – camille Sep 18 '21 at 21:04
1

Since macOS 10.10 you can use a CIFilter to read QRCodes without the need for any third-party framework:

Here's the link to the official docs, and to a blog post that shows how to use it.

pfandrade
  • 2,359
  • 15
  • 25
1

When attempting to create and read a barcode you could use a paid for macOS framework. The LEADTOOLS SDK BarcodeReader and BarcodeWriter classes can both read and write barcodes and can be used in both Objective-C and Swift projects.

https://www.leadtools.com/help/sdk/v21/dh/ba/barcodewriter.html

When creating a barcode you will need to provide the necessary barcode data and options needed when writing.

        LTBarcodeData * const barcodeData = writeBarcodeView.barcodeData;

        _selectedSymbology = writeBarcodeView.selectedSymbology;

        _indexOfSelectedWriteOption = writeBarcodeView.indexOfSelectedWriteOption;

        

        LeadRect writeBounds = LeadRectMake(0, 0, image.width, image.height);

        

        if (!LeadRectIsZero(writeBounds) && !LeadRectEqualToRect(writeBounds, barcodeData.bounds))

            writeBounds = barcodeData.bounds;

        

        for (LTBarcodeWriteOptions *writeOption in _barcodeEngine.writer.allDefaultOptions) {

            writeOption.foreColor = [writeBarcodeView.foreColorWell.color colorUsingColorSpaceName:NSCalibratedRGBColorSpace].LTRasterColor;

            

            NSColor * const color = [writeBarcodeView.backColorWell.color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];

            writeOption.backColor = [NSColor colorWithSRGBRed:color.redComponent green:color.greenComponent blue:color.blueComponent alpha:1.0].LTRasterColor;

        }

        

        NSError *error = nil;

        if (![_barcodeEngine.writer calculateBarcodeDataBounds:writeBounds xResolution:image.xResolution yResolution:image.yResolution data:barcodeData options:nil error:&error]) {

            [self displayAlertWithMessage:@"Error while writing barcode" informativeText:error.localizedDescription];

            return;

        }

        

        if (![_barcodeEngine.writer writeBarcode:image data:barcodeData options:nil error:&error]) {

            [self displayAlertWithMessage:@"Error while writing barcode" informativeText:error.localizedDescription];

            return;

        }

        

        _imageViewer.rasterImage = image;

https://www.leadtools.com/help/sdk/v21/dh/ba/barcodereader.html

Here is a small code snippet in searching an image for a barcode

NSArray<LTBarcodeData *> *barcodeData = [_barcodeEngine.reader readBarcodes:processingImage searchBounds:bounds maximumBarcodes:0 symbologies:nil error:&error];

There is an example macOS application that uses the LEADTOOLS SDK framework that is currently hosted on the Mac App Store. https://apps.apple.com/us/app/leadtools-barcode/id602159087

Kurt
  • 11
  • 1