使用的第三方库ZXingObjC(https://github.com/TheLevelUp/ZXingObjC)进行识别,主要代码如下:
CGImageRef imageToDecode = image.CGImage; // Given a CGImage in which we are looking for barcodes
ZXLuminanceSource *source = [[ZXCGImageLuminanceSourcealloc] initWithCGImage:imageToDecode];
ZXBinaryBitmap *bitmap = [ZXBinaryBitmapbinaryBitmapWithBinarizer:[ZXHybridBinarizerbinarizerWithSource: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 = [ZXDecodeHintshints];
ZXMultiFormatReader *reader = [ZXMultiFormatReaderreader];
ZXResult *result = [reader decode:bitmap
hints:hints
error:&error];
if (result) {
NSString *contents = result.text;
NSLog(@"%@",contents);
}else {
}
if ((image.size.width >280)&&(image.size.height >280))
{
image = ;//使用图片缩小函数,网上有很多代码都可以的
}
然后就可以识别了。从相册里导入图片,我就省了,自己从网上找。