英文:
zxing generate QR code with logo in center just like whatsapp web QR code
问题
我想使用 zxing
和 Java
创建带有标志的 QR code
,就像 WhatsApp Web 上的 QR code
一样。
以下是生成简单 QR code
的示例代码:
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.imageio.ImageIO;
public class Test {
public static void main(String[] args) {
int QRCODE_IMAGE_HEIGHT = 250;
int QRCODE_IMAGE_WIDTH = 250;
String IMAGE_PATH = "pictures";
QRCodeWriter qrWriter = new QRCodeWriter();
BitMatrix matrix;
try {
matrix = qrWriter.encode("qrcode qrcode qrcode qrcode", BarcodeFormat.QR_CODE, QRCODE_IMAGE_WIDTH, QRCODE_IMAGE_HEIGHT);
BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);
File imageFile = new File(IMAGE_PATH, "qrcode.png");
ImageIO.write(image, "PNG", imageFile);
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
生成的结果:
但我想要类似于下面这样的效果:
英文:
I would like to create QR codes
with zxing
AND Java
but with logo in center just like whatsapp web QR code
.
Here's an example for my simple QR code generated.
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.imageio.ImageIO;
public class Test {
public static void main(String[] args) {
int QRCODE_IMAGE_HEIGHT = 250;
int QRCODE_IMAGE_WIDTH = 250;
String IMAGE_PATH = "pictures";
QRCodeWriter qrWriter = new QRCodeWriter();
BitMatrix matrix;
try {
matrix = qrWriter.encode("qrcode qrcode qrcode qrcode", BarcodeFormat.QR_CODE, QRCODE_IMAGE_WIDTH, QRCODE_IMAGE_HEIGHT);
BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);
File imageFile = new File(IMAGE_PATH, "qrcode.png");
ImageIO.write(image, "PNG", imageFile);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
result :
but i want something like this :
答案1
得分: 1
- 所有的 QR 码都带有类似纠错位的内容。因此,如果您隐藏了 QR 码的一小部分,它仍然可以正常工作。您可以覆盖多少部分取决于 QR 码的大小和纠错位的数量。
- 您可以生成带有更多纠错位的 QR 码(例如 BMP 图像)。然后,您可以从其他地方获取您的徽标/图像,并将您的图像放在 QR 图像上。
英文:
- All qr codes have something like correction bit. So if you will hide some small part of qr code, it will be still working. How much you can cover depends on size of qr code and amount of correction bit.
- You can generate qr code (with some bigger amout of correction bit) as e.g bmp image. Then you can get from somewhere your logo/imge and put your image on qr image.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论