iOS:ZBar SDK unicode字符 [英] iOS: ZBar SDK unicode characters
问题描述
使用ZBar扫描QR码时,进程产生的字符串不能正确显示unicode字符。 Márti这个词由任何免费使用QR码生成器编码为QR码(如 http:/ /qrcode.kaywa.com )会导致 Mテ.rti 。
When scanning QR codes with ZBar the string resulting from the process does not display unicode characters properly. The word Márti encoded as a QR code by any free to use QR code generator (like http://qrcode.kaywa.com) would result in Mテ。rti.
在其他SO问题中(1 , 2 )建议在结果字符串的开头嵌入BOM,但这样做:
In other SO questions (1, 2) it was suggested to embed a BOM at the start of the resulting string, but doing this:
NSString *qrString = [NSString stringWithFormat:@"\xEF\xBB\xBF%@",symbol.data];
或者这个:
NSString *qrString = [[NSString alloc] initWithFormat:@"\357\273\277%@", symbol.data];
导致与亚洲角色相同,有缺陷的结果。 symbol.data
是由ZBar提供的结果NSString。
resulted in the same, flawed result with the Asian character. symbol.data
is the resulting NSString provided by ZBar.
更新:根据dda的答案,解决方案如下:
NSString *qrString = symbol.data;
//look for misinterpreted acute characters and convert them to UTF-8
if ([qrString canBeConvertedToEncoding:NSShiftJISStringEncoding]) {
qrString = [NSString stringWithCString:[symbol.data cStringUsingEncoding: NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];
}
推荐答案
我可以创建二维码日本语(日语)和Márti及以下图书馆:
I could create QR codes of "日本語"(japanese) and "Márti" with following libraries:
- iOS-QR-Code-Encoder
- QR-Code-Encoder-for-Objective-C.
您可以使用ZBar读取这些QR码。
You can read those QR codes with ZBar.
NSString* orginalString = @"Márti"(or "日本語"(japanese));
NSString *data = [[NSString alloc] initWithFormat:@"\357\273\277%@", orginalString];
UIImage* qrcodeImage = [QRCodeGenerator qrImageForString:data imageSize:imageView.bounds.size.width];
QR-Code-Encoder-for-Objective-C :
NSString* orginalString = @"Márti"(or "日本語"(japanese));
NSString *data = [[NSString alloc] initWithFormat:@"\357\273\277%@", orginalString];
//first encode the string into a matrix of bools, TRUE for black dot and FALSE for white. Let the encoder decide the error correction level and version
DataMatrix* qrMatrix = [QREncoder encodeWithECLevel:QR_ECLEVEL_AUTO version:QR_VERSION_AUTO string:data];
//then render the matrix
UIImage* qrcodeImage = [QREncoder renderDataMatrix:qrMatrix imageDimension:qrcodeImageDimension];
这篇关于iOS:ZBar SDK unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!