[JAVA] [Android] Read from QR code image with zxing

I tried reading from an image containing a QR code using zxing. ZXing Android Embedded

void readQrcode(Bitmap bitmap) {
    //Get the size of the Bitmap and get the pixel data
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    try {
        //Convert to Binary Bitmap format that can be handled by zxing
        LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
        //Read and analyze image data with zxing
        Reader reader = new MultiFormatReader();
        Result decodeResult = reader.decode(binaryBitmap);
        //Get the analysis result
        String result = decodeResult.getText();
        Log.d("readQR", result);
    } catch (Exception e) {
        Log.d("readQR", e.getLocalizedMessage());
    }
}

Omit the part that reads from the file and gets the Bitmap!

Recommended Posts

[Android] Read from QR code image with zxing
Read and generate QR code [Android]
Code Java from Emacs with Eclim
[Android] A story that stumbled when introducing ZXing, a QR code function library
Find Raspberry Pi from Android with mDNS
Execute Java code from cpp with cocos2dx
Clean up findViewById from source code with DataBindingLibrary
[Ruby] Generate a concatenated QR code with rqrcode (Knowledge)
[Spring] Read a message from a YAML file with MessageSource
Vibrate the wristband device with Bluetooth from the Android app
[Ruby] Generate a concatenated QR code with rqrcode (Practice)
Build an Android image for Orange Pi 4 with Docker
Read temperature / humidity with Java from Raspberry Pi 3 & DHT11
How to read a library from a JAR file with VS Code << How to not use Maven / Gradle >>