关于二维码编码与解码中使用技术分析

主要是基于分析zxing生成与解析二维码的过程,结合二维码标准来说道。

BitMatrix

存储的数据结构类:com.google.zxing.common.BitMatrix
BitMatrix 表示位的二维矩阵。原点在左上角,x 是列位置,y 是行位置。顺序总是 x, y。
在内部的实现,是以32位整数的一维数组表示来存储每一位。
但是每一行都以一个新的int开头。以便我们可以非常有效地将一行复制到 BitArray 中。

分析下构造函数:

1
2
3
4
5
6
7
8
9
10
11
private final int width;
private final int height;
private final int rowSize;
private final int[] bits;

public BitMatrix(int width, int height) {
this.width = width;
this.height = height;
this.rowSize = (width + 31) / 32;
bits = new int[rowSize * height];
}
1
2
3
4
5
6
7
8
9
public void set(int x, int y) {
int offset = y * rowSize + (x / 32);
bits[offset] |= 1 << (x & 0x1f);
}

public void unset(int x, int y) {
int offset = y * rowSize + (x / 32);
bits[offset] &= ~(1 << (x & 0x1f));
}

需要熟悉位的操作
每一行用一个整型数组每一位来存储。
这样是为

QRCode

QRCode 二维码对象

Mode

https://www.iso.org/obp/ui/#iso:std:iso-iec:18004:ed-2:v1:en

请参阅 ISO 18004:2006、6.4.1、表 2 和 3。此枚举封装了可将数据编码为 QR 码标准中的位的各种模式


关于二维码编码与解码中使用技术分析
https://blog.fengcl.com/2021/09/19/qr-code-analysis/
作者
frank
发布于
2021年9月19日
许可协议