Java的条形码图像处理库 – ZXingObjC

weixin_38081402 2019-09-12 11:58:53
ZXingObjC ZXingObjC是一个ZXing的全Objective-C端口,一个Java的条形码图像处理库 目前支持下列条码的编码和解码: UPC-A and UPC-E EAN-8 and EAN-13 Code 39 Code 128 ITF Codabar RSS-14 QR Code Data Matrix Aztec  PDF 417  使用方法 编码: 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]; }解码: 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. }
...全文
13 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧