Background introduction:
Recently, we need to make an automatic QR code generation and embed the QR code into the existing background template. We have never written these things, and it is a bit confused after suddenly writing it, especially because we are not very familiar with the Java image API, so we refer to the sharing of many netizens and have made it quickly. Let's share it now.
Notice:
Regarding the generation method of QR codes, the article java generates colorful QR codes with logos, and everyone can use them together.
Example code:
BufferedImage image= bim;//QR code BufferedImage bg= ImageIO.read(path);//Get Beijing image Graphics2D g=bg.createGraphics();int width=image.getWidth(null) > bg.getWidth() * 5/10? (bg.getWidth() * 5/10) : image.getWidth(null);int height=image.getHeight(null) > bg.getHeight() *5 /10? (bg.getHeight() * 5/10) : image.getWidth(null);g.drawImage(image,(bg.getWidth()-width)/2,(bg.getHeight()-height)/2,width,height,null);g.dispose();bg.flush();image.flush();ImageIO.write(bg,"png", file);
The renderings of the QR code:
Summarize
The above is the content that automatically generates QR codes and existing background images using Java. Friends in need can refer to it.