【发布时间】:2019-03-11 01:38:25
【问题描述】:
嗯,我正在用 QR 码做一个项目。我的项目的想法是结合二维码的数字(我的项目是8个二维码)生成一个单色二维码,这个想法是增加二维码的数据存储。
然而,到目前为止,我已经完成了大部分工作,但我留下了最重要的部分,即生成彩色 QR 码。彩色二维码必须使用十六进制颜色生成,并将颜色设置为二维码的每个像素,使其类似于彩色二维码。现在,我会尝试使用红色 1st 生成。
所以我将binary 值存储在ArrayList 中,数据类似于10101010。然后我将其更改为十六进制。这是我的代码:
ArrayList<String>arrayList = new ArrayList<>();
arrayList.add(a1+a2+a3+a4+a5+a6+a7+a8); // Store 1110001 into ArrayList
String [] hexArray = new String[arrayList.size()];
arrayList.toArray(hexArray);
for(int a = 0; a < hexArray.length; a++){
int dec = Integer.parseInt(String.valueOf(arrayList.get(a)),2);
String hexString = Integer.toString(dec, 16);
String alpha = "0xff";
String behind = "0000";
hexArray[a] = alpha+hexString+behind;
}
我写了一些改变颜色的代码,但是代码改变了二维码的整个颜色,也就是二维码的前景和背景。
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;
}
因为 ARGB 具有 Alpha、Red、Green、Blue 颜色。 如果我只想将十六进制值设置为红色怎么办。然后将二维码的每个像素设置为红色(红色的种类会略有不同,因为十六进制值不同)二维码。
【问题讨论】:
-
I need the solution不是寻求帮助的正确方式。此外,链接问题中至少有足够的信息可以尝试将两个不同的 QR 码叠加为一个具有三种颜色的二维码:数据 1 颜色、数据 2 颜色和重叠像素的黑色。您必须修改 QR 阅读器以取消图像分层,但我认为这就是您想要做的。无论如何,请通过尝试或有关问题的更多详细信息来更新您的问题。