java to objc_Java的条形码图像处理库 – ZXingObjC

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.

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值