zxing生成带有位于中心的Logo的QR码,就像WhatsApp Web的QR码。

huangapple go评论75阅读模式
英文:

zxing generate QR code with logo in center just like whatsapp web QR code

问题

我想使用 zxingJava 创建带有标志的 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();
        }
    }
}

生成的结果:

zxing生成带有位于中心的Logo的QR码,就像WhatsApp Web的QR码。

但我想要类似于下面这样的效果:

zxing生成带有位于中心的Logo的QR码,就像WhatsApp Web的QR码。

英文:

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 :

zxing生成带有位于中心的Logo的QR码,就像WhatsApp Web的QR码。

but i want something like this :

zxing生成带有位于中心的Logo的QR码,就像WhatsApp Web的QR码。

答案1

得分: 1

  1. 所有的 QR 码都带有类似纠错位的内容。因此,如果您隐藏了 QR 码的一小部分,它仍然可以正常工作。您可以覆盖多少部分取决于 QR 码的大小和纠错位的数量。
  2. 您可以生成带有更多纠错位的 QR 码(例如 BMP 图像)。然后,您可以从其他地方获取您的徽标/图像,并将您的图像放在 QR 图像上。
英文:
  1. 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.
  2. 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.

https://stackoverflow.com/a/35104430

huangapple
  • 本文由 发表于 2020年9月30日 04:00:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/64126798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定