Using Java to realize merging _java of two-dimensional code and background image

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.