在我的项目中是这样用的,只要加上这句就行:
NSString *textd = symbol.data;
//解决中文乱码问题
if ([textd canBeConvertedToEncoding:NSShiftJISStringEncoding])
{
textd = [NSString stringWithCString:[textd cStringUsingEncoding:
NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];
}
resultText.text = [NSString stringWithFormat:@"%@",textd]; //这个就是它扫描出来的文字信息,(下边加载Libzbar时的那段代码我也没写)
转载自:http://blog.csdn.net/huanghuanghbc/article/details/9173023
使用ZbarSDK来构建二维码扫描
如果你的应用中需要用到二维码扫描功能,Zbar是一个不错的选择。1,先去官方地址下载最新的包 http://sourceforge.net/projects/zbar/
我现在用的是SDK1.3.1 这个版本的库支持armv7s,如果是下载的早期的版本就不支持armv7s,会多一些额外的步凑
2,把相关的源码和libzbar.a加入项目中,导入库 AVFoundation.framwork, CoreMedia.framework, CoreVideo.framework, libiconv.dylib
3,在使用时 #import "ZBarSDK.h" 并实现委托 ZBarReaderDelegate
一般只需要实现的委托方法为:
- (void) imagePickerController: (UIImagePickerController*) reader加载zbar时的代码:
didFinishPickingMediaWithInfo: (NSDictionary*) info{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
NSString *textd = symbol.data;
//解决中文乱码问题
if ([textd canBeConvertedToEncoding:NSShiftJISStringEncoding])
{
textd = [NSString stringWithCString:[textd cStringUsingEncoding:
NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];
}
resultText.text = [NSString stringWithFormat:@"%@",textd];
resultImage.image = [info objectForKey: UIImagePickerControllerOriginalImage];
[reader dismissModalViewControllerAnimated: NO];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissModalViewControllerAnimated: YES];
[self.navigationController popViewControllerAnimated:NO];
}
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self presentModalViewController: reader
animated: NO];