2013-02-20 52 views
0

我正在修改一个基于开源项目zxing的二维码项目,但是当我输入中文字符时,我发现从其他二维码软件得到的结果总是以“] Q2 \ 000026 “ 字首。我无法理解它的含义。使用zxing-2.1版本。这里是项目链接http://code.google.com/p/zxing/有没有人有修改关于zxing的二维码项目的经验?

我的项目的代码是:

@Override 
public void run() { 
    // TODO Auto-generated method stub 
       try { 
      mTextContent = chinese test 中文测试"; 
      Bitmap bitmap = Create2DCode(mTextContent); 
      return; 
     } catch (WriterException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
} 

public Bitmap Create2DCode(String str) throws WriterException { 
    Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); 
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q); 
    hints.put(EncodeHintType.CHARACTER_SET, "GBK");//UTF-8 
    // hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");//It's the same result. 
    BitMatrix matrix = new MultiFormatWriter().encode(str,BarcodeFormat.QR_CODE, 500, 500, hints); 
    int width = matrix.getWidth(); 
    int height = matrix.getHeight(); 
    int[] pixels = new int[width * height]; 
    for (int i = 0; i < pixels.length; i++) { 
     pixels[i] = 0xffffffff; 
    } 
    for (int y = 0; y < height; y++) { 
     for (int x = 0; x < width; x++) { 
      if (matrix.get(x, y)) { 
       pixels[y * width + x] = 0xff000000; 
      } 
     } 
    } 
    Bitmap bitmap = Bitmap.createBitmap(width, height, 
      Bitmap.Config.ARGB_8888); 
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height); 
    return bitmap; 
} 

任何人都可以给我一些帮助吗?

+1

你试过其他口味的UTF吗?例如UTF16? – alex 2013-02-20 03:16:37

+0

是的,我试过UTF-8,它仍然存在这个问题,我用UTF-16失败了。我认为这可能与新版本对中文的支持有些问题,因为我发现旧版本没有出现这个问题。 – user2089487 2013-02-20 04:08:04

回答

0

我认为您使用的QR软件可能不支持它。因为我曾经使用过zxing lib并编写如下代码。中文可以通过名为“wochacha”的应用程序识别,但不能通过“微信”识别

Map hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET,“UTF8”); BitMatrix matrix = new MultiFormatWriter()。encode(str,BarcodeFormat.QR_CODE,400,400,hints);

相关问题