Java Custom Center picture generation with parameter Unlimited applet code __ static function

Source: Internet
Author: User

In fact, the central picture of small program code can not be customized, using the basic information in the small program head. So, don't think about customizing things. But we can do some work on the generated small code to achieve this effect, the use is actually Java graphics2d drawing. The process is as follows:

1, generate small program code, see this blog Java generate unrestricted with parameter small program code

2, 1 steps to obtain a small code picture, to prepare a size and center size more appropriate picture, the following code is used to replace the central area of the

public class Test {public static void main (string[] args) {try {bufferedimage Apple
            timg = Imageio.read (New FileInputStream ("D:\\applet.png"));

            Graphics2D g2d = Appletimg.creategraphics ();
            Set anti-aliasing properties G2d.setrenderinghint (renderinghints.key_antialiasing, renderinghints.value_antialias_on);

            G2d.setrenderinghint (renderinghints.key_text_antialiasing, renderinghints.value_text_antialias_on);
            BufferedImage centerimg = Imageio.read (New File ("D:\\center.png")); G2d.drawimage (Centerimg.getscaledinstance (Centerimg.getwidth (), Centerimg.getheight (), Image.SCALE_SMOOTH), (

            Appletimg.getwidth ()-centerimg.getwidth ())/2, (Appletimg.getheight ()-centerimg.getheight ())/2, NULL);
            Close resource G2d.dispose ();
        Imageio.write (appletimg, "PNG", New File ("D:\\newapplet.png"));
   catch (Exception e) {e.printstacktrace ();     }
    }
} 

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.