munir ishak 08a7ebefa5 initial commit | 4 vuotta sitten | |
---|---|---|
.. | ||
ZXingObjC | 4 vuotta sitten | |
ZXingObjC.xcodeproj | 4 vuotta sitten | |
.gitattributes | 4 vuotta sitten | |
.npmignore | 4 vuotta sitten | |
AUTHORS | 4 vuotta sitten | |
AUTHORS-ZXingObjC | 4 vuotta sitten | |
COPYING | 4 vuotta sitten | |
NOTICE | 4 vuotta sitten | |
README.md | 4 vuotta sitten | |
ZXingObjC.podspec | 4 vuotta sitten | |
ios-Info.plist | 4 vuotta sitten | |
ios-Prefix.pch | 4 vuotta sitten | |
mac-Info.plist | 4 vuotta sitten | |
osx-Prefix.pch | 4 vuotta sitten |
ZXingObjC is a full Objective-C port of ZXing (“Zebra Crossing”), a Java barcode image processing library. It is designed to be used on both iOS devices and in Mac applications.
The following barcodes are currently supported for both encoding and decoding:
ZXingObjC currently has feature parity with ZXing version 3.0.
Sorry, this project had some sort of winter sleep for a long time. There were also some ideas to rewrite this project in Swift. Instead of rewriting the project in Swift as a whole, we planned to keep up feature parity with zxing-core at first, then rewrite the capture module as well as the examples in Swift. From this new starting point, we are going to replace classes step-by-step with new Swift implementations. We do not want to create a new barcode scanner but to keep the code as similar as possible to zxing-core.
ZXingObjC requires Xcode 8.3.3, targeting either iOS 8.0 and above, or Mac OS X 10.8 Mountain Lion and above.
Encoding:
NSError *error = nil;
ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
ZXBitMatrix* result = [writer encode:@"A string to encode"
format:kBarcodeFormatQRCode
width:500
height:500
error:&error];
if (result) {
CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage];
// This CGImageRef image can be placed in a UIImage, NSImage, or written to a file.
} else {
NSString *errorMessage = [error localizedDescription];
}
Decoding:
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.
}
We highly recommend Carthage as module manager.
Alternatively, ZXingObjC can be installed using Carthage. After installing Carthage just add ZXingObjC to your Cartfile:
github "TheLevelUp/ZXingObjC" ~> 3.2.1
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. After installing CocoaPods add ZXingObjC to your Podfile:
platform :ios, '7.0'
pod 'ZXingObjC', '~> 3.2.1'
ZXingObjC includes several example applications found in “examples” folder:
ZXingObjC is available under the Apache 2.0 license.