2

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 :

qr code generated

but i want something like this :

enter image description here

ZINE Mahmoud
  • 1,272
  • 1
  • 17
  • 32

1 Answers1

2
  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

Grzegorz
  • 169
  • 4