2013-02-20 54 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);

相關問題