I am trying to generate a QR code using Zxing on Android. Since java.awt.image.BufferedImage is not included in Android, I am not sure how to create the QR code image on Android.
EDIT: I don't want my application to require internet access.
I found this to be a helpful http://codeisland.org/2013/generating-qr-codes-with-zxing/
Using the above resource, I created a utility method as follows:
public static Bitmap encodeToQrCode(String text, int width, int height){
    QRCodeWriter writer = new QRCodeWriter();
    BitMatrix matrix = null;
    try {
        matrix = writer.encode(text, BarcodeFormat.QR_CODE, 100, 100);
    } catch (WriterException ex) {
        ex.printStackTrace();
    }
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    for (int x = 0; x < width; x++){
        for (int y = 0; y < height; y++){
            bmp.setPixel(x, y, matrix.get(x,y) ? Color.BLACK : Color.WHITE);
        }
    }
    return bmp;
}
                        Please look at the zxing source code under android/. In the .encode package you will see an example of exactly how to encode a QR code in Android. Yes, you can't use, and don't need to use BufferedImage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With