4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Android] zxingでQRコード画像から読み取る

Posted at

QRコードを含む画像からの読み取りを、zxing を使って行ってみました。
ZXing Android Embedded

void readQrcode(Bitmap bitmap) {
    // Bitmap のサイズを取得して、ピクセルデータを取得する
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    try {
        // zxing で扱える BinaryBitmap形式に変換する
        LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
        // zxing で画像データを読み込み解析する
        Reader reader = new MultiFormatReader();
        Result decodeResult = reader.decode(binaryBitmap);
        // 解析結果を取得する
        String result = decodeResult.getText();
        Log.d("readQR", result);
    } catch (Exception e) {
        Log.d("readQR", e.getLocalizedMessage());
    }
}

ファイルから読み込んで Bitmap を取得する部分は省略します!

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?