ZXingObjCFork 3.6.5

ZXingObjCFork 3.6.5

huawt 维护。



  • zxingify

zxingify-objc

ZXingObjC 是 ZXing ("Zebra Crossing") 的完整 Objective-C 版,一个 Java 条码图像处理库。它旨在同时在 iOS 设备上和 Mac 应用程序中使用。

以下条码目前都支持编码和解码

  • UPC-A 和 UPC-E
  • EAN-8 和 EAN-13
  • Code 39
  • Code 93
  • Code 128
  • ITF
  • Codabar
  • RSS-14 (所有变体)
  • QR 码
  • Data Matrix
  • Maxicode
  • Aztec ('beta' 质量)
  • PDF 417 ('beta' 质量)

ZXingObjC 目前与 ZXing 3.3.3 版本的特性相同。

需求

ZXingObjC 需要 Xcode 8.3.3 或以上版本,目标平台为 iOS 8.0 或以上,或者 Mac OS X 10.8 Mountain Lion 或以上。

用法

编码

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 = CGImageRetain([[ZXImage imageWithMatrix:result] cgimage]);

  // This CGImageRef image can be placed in a UIImage, NSImage, or written to a file.
  
  CGImageRelease(image);
} else {
  NSString *errorMessage = [error localizedDescription];
}

解码

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.
}

安装

我们强烈推荐使用 Carthage 作为模块管理器。

Carthage

ZXingObjC 可以通过 Carthage 进行安装。安装 Carthage 之后,只需在 Cartfile 中添加 ZXingObjC 即可。

github "TheLevelUp/ZXingObjC" ~> 3.6

CocoaPods

CocoaPods 是 Swift 和 Objective-C 创建的 Cocoa 项目的依赖管理器。安装 CocoaPods 后,将 ZXingObjC 添加到 Podfile。

platform :ios, '8.0'
pod 'ZXingObjC', '~> 3.6.4'

示例

ZXingObjC 包含了位于 "examples" 文件夹中的几个示例应用程序

  • BarcodeScanner - 一个捕获相机视频的 iOS 应用,扫描二维码并在屏幕上显示结果。
  • BarcodeScannerSwift - 一个捕获相机视频的 iOS 应用,扫描二维码并在屏幕上显示结果,完全使用 Swift 重新编写。

致谢

  • cwalcott 是此项目的最初创建者
  • neacao 因其在最近的无与伦比的支持
  • claybridges 在项目迁移方面的所有帮助

许可

ZXingObjC 在 Apache 2.0 许可证 下可用。