Extract the data from QR Codes and create a new QR code with colour

Kop*_*ant 5 android qr-code zxing

Has anyone heard of this before ? Extract the QR Codes (all the QR Codes must be in same Width and Height {square}) and get the data from each QR Code, and combine them. Then get the every pixel value from each QR Code and change them to hexadecimal. You will give #FFFFFFFF, #FF000000, #00000000 (white,black, transparent) and the like (but for black and white QR Code, it would only 2 of them). Then for each value from each QR Code, by creating a new colour QR Code which the colour is according to the value from each hexadecimal and the content of the new colour QR Code will have the content that was extracted from the previous QR Codes.

For example, what I am doing now is extract 8 numbers of QR Code and combine the content, then create a new colour QR Code.

By now, I am stuck in the middle of the process. I have successfully extracted the content and the pixel of each QR Code by changing the value to hexadecimal. the problem is how can I can change the hexadecimal value from each QR code to ARGB (alpha, Red, Green, Blue) colour and create a new colour QR Code.

However, I have tip from Google, some say MatrixToImageWriter would be useful. But there is not really much work there that is similar and useful to me. Well, I need some help here. However, I am not sure whether it will be useful for me or not.

PS: I can attach my work here if someone want to.

PSS:我正在使用该Zxing库进行扫描,并从中获取结果QR Code

Mar*_*ler 5

我已经编写了所需的解码/编码方法;矩阵看起来有所不同,因为我已经使用QR Droid应用程序创建了输入QR代码,并使用ZXing创建了输出QR代码,这可能会使用不同级别的错误校正;不过,两者都有相同的目标网址,这是我的。

依赖项来自存储库google()mavenCentral()

dependencies {

    implementation "androidx.appcompat:appcompat:1.0.2"

    // https://mvnrepository.com/artifact/com.google.zxing
    implementation "com.google.zxing:core:3.3.3"
    implementation "com.google.zxing:android-core:3.3.0"
}
Run Code Online (Sandbox Code Playgroud)

使用的布局资源:

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/inputImage"
        android:src="@drawable/qrcode"
        android:layout_height="200dp"
        android:layout_width="200dp"
        android:padding="8dp"/>

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/outputImage"
        android:layout_height="200dp"
        android:layout_width="200dp"
        android:padding="8dp"/>

</androidx.appcompat.widget.LinearLayoutCompat>
Run Code Online (Sandbox Code Playgroud)

和操纵BitMatrix; 该encode()方法应在哪里String可用,何时可用;只是为了一个完整的示例添加了这两种方法(它Bitmap从一个方法中读取AppCompatImageView,然后写入另一个方法中AppCompatImageView):

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;

public class MainActivity extends AppCompatActivity {

    private AppCompatImageView mInputImage;
    private AppCompatImageView mOutputImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.layout_main);

        this.mInputImage = this.findViewById(R.id.inputImage);
        this.mOutputImage = this.findViewById(R.id.outputImage);

        Bitmap bitmap = ((BitmapDrawable) this.mInputImage.getDrawable()).getBitmap();
        String data = this.decode(bitmap);

        bitmap = this.encode(data, bitmap.getWidth(), bitmap.getHeight(), 0xFFFFD034,0xFF06425C);
        this.mOutputImage.setImageBitmap(bitmap);
    }

    private String decode(Bitmap bitmap) {

        String data = null;
        MultiFormatReader reader = new MultiFormatReader();
        int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
        bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
        LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
        BinaryBitmap binary = new BinaryBitmap(new HybridBinarizer(source));

        try {
            Result result = reader.decode(binary);
            data = result.getText();
        } catch (NotFoundException e) {
            e.printStackTrace();
        }

        Log.d("ZXing", "decoded: " + data);
        return data;
    }

    private Bitmap encode(String contents, int width, int height, @ColorInt int foreground, @ColorInt int background) {

        MultiFormatWriter writer = new MultiFormatWriter();
        BitMatrix matrix = null;
        Bitmap bitmap = null;

        try {
            matrix = writer.encode(contents, BarcodeFormat.QR_CODE, width, height);
        } catch (WriterException e) {
            e.printStackTrace();
        }

        if(matrix != null) {
            int[] pixels = new int[width * height];
            for (int y = 0; y < height; y++) {
                int offset = y * width;
                for (int x = 0; x < width; x++) {
                    pixels[offset + x] = matrix.get(x, y) ? foreground : background;
                }
            }
            bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        }

        return bitmap;
    }
}
Run Code Online (Sandbox Code Playgroud)

结果看起来像这样;其中左边一个是输入矩阵,右边一个是输出矩阵:

QR码,输入和输出矩阵