Android Question Update zxing lib to make it Create QR Code

chjk

Member
Licensed User
Longtime User
I add the following code in b4aZXingLib.java
B4X:
    /**
    * Create QR Code
    * @param str
    * @author chjk
    * @return Bitmap
    * @throws WriterException
    */
    public Bitmap Create2DCode(String str) throws WriterException, UnsupportedEncodingException {
    
        BitMatrix matrix = new MultiFormatWriter().encode(new String(str.getBytes("GBK"),"ISO-8859-1"),BarcodeFormat.QR_CODE, 300, 300);
    
        int width = matrix.getWidth();
        int height = matrix.getHeight();
        int[] pixels = new int[width * height];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if(matrix.get(x, y)){
                    pixels[y * width + x] = 0xff000000;
                }
            
            }
        }
        //int[] colors={R.color.white};
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    
        bmp.setPixels(pixels, 0, width, 0, 0, width, height);
        return bmp;
    }
}
Create zxinglib is normal, but the reference problem. Zxing ver 2.3
Download src Link:http://www.b4x.com/android/forum/threads/update-zxing-lib-to-make-it-create-2d-code.36659/
 
Top