Background information:
Recently we need to do an automatic generation of two-dimensional code and also to the two-dimensional code embedded in the existing background template, has not written these aspects of things, suddenly write is really a bit confused, especially for the Java Picture API is not very familiar with, so reference a lot of netizens share, quickly made, now share
Attention:
On the generation of two-dimensional code in the article Java generation with a logo of the colorful two-dimensional code has been written, we can together use.
Instance code:
BufferedImage image= bim;//Two-dimensional code
bufferedimage bg= imageio.read (path);//Get Beijing pictures
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);
Two-dimensional code effect diagram:
Summarize
The above is the use of Java implementation automatically generated two-dimensional code and the existing background image merged content, the need for friends can refer to learning.