0

我正在修改一个基于开源项目zxing的二维码项目,但是当我输入汉字时,发现从其他二维码软件得到的结果总是以“]Q2 \ 000026”为前缀. 我不明白这是什么意思。使用zxing-2.1版本。这是项目链接http://code.google.com/p/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;
}

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

4

1 回答 1

0

我认为您使用的二维码软件可能不支持它。因为我曾经使用过 zxing lib 并编写了如下代码。中文可以被叫“wochacha”的应用识别,但不能被“wechat”识别

地图提示 = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); BitMatrix 矩阵 = new MultiFormatWriter().encode(str,BarcodeFormat.QR_CODE, 400, 400, hints);

于 2013-07-09T03:11:13.093 回答