JAVA------20. Inserting text and pictures in a picture

Source: Internet
Author: User

ImportJava.awt.Color;ImportJava.awt.Font;ImportJava.awt.Graphics2D;ImportJava.awt.Image;ImportJava.awt.image.BufferedImage;ImportJava.io.File;ImportJava.net.URL;ImportJavax.imageio.ImageIO; Public classPicturedemo {/*** Compositing the image *@parambigpath main map picture path *@paramSmallpath Product Picture path *@paramErweimapath Two-dimensional code picture path*/       Public Static Final voidoverlapimage (String bigpath, String smallpath,string erweimapath) {Try{BufferedImage Big= Imageio.read (NewFile (Bigpath)); URL URL=NewURL ("Http://mjj.dapail.com/app/moneyUrl.png"); BufferedImage Small=Imageio.read (Url.openstream ()); BufferedImage Erweima= Imageio.read (NewFile (Erweimapath)); /*int width=2015; int height=1136;*/          intwidth=400; intheight=600; Image Image=big.getscaledinstance (width, height, image.scale_smooth); BufferedImage BufferedImage2=Newbufferedimage (width, height, bufferedimage.type_int_bgr); Graphics2D g=Bufferedimage2.creategraphics (); /*int x = 707;            int y = 268;            int x1 = 684; int y1 = 245;*/                    intx = 200; inty = 250; intX1 = 200; intY1 = 250; G.drawimage (Image,0, 0,NULL); //g.drawimage (small,x1-200, y1-250, (+), (+), NULL); //Red EnvelopesG.drawimage (small, X, y+100, 50, 50,NULL); //g.drawimage (Erweima, x1-575, y1+100, 596, 596, NULL); //Two-dimensional codeG.drawimage (Erweima, x1-100, y1+80, 200, 200,NULL); Font Font=NewFont ("Blackbody", Font.plain, 25);            G.setfont (font);            G.setpaint (Color.dark_gray); intNumwidth =x-70; intNumhright=y+50; intNum=0; //g.drawstring ("Product Name:", numwidth,numhright); //g.drawstring ("Test chess Room", numwidth,numhright);String name= "Test test testing test test"; if(Name.length () ==2) {Numwidth=x-20; }          Else if(Name.length () ==3) {Numwidth=x-35; }Else if(Name.length () ==4) {Numwidth=x-50; }Else if(Name.length () ==5) {Numwidth=x-65; }Else if(Name.length () ==6) {Numwidth=x-75; }Else if(Name.length () ==7) {Numwidth=x-90; }Else if(Name.length () ==8) {Numwidth=x-105; }          Else if(Name.length () ==9) {Numwidth=x-115; }          Else if(Name.length () ==10) {Numwidth=x-130; }          Else if(Name.length () ==11) {Numwidth=x-145; }          Else if(Name.length () ==12) {Numwidth=x-160;                 } g.drawstring (name, numwidth,numhright); /*G.setpaint (Color.dark_gray);            Font font1=new font ("Song Body", Font.Bold, 15);          G.setfont (FONT1);          numwidth=numwidth-25; g.DrawString ("Jiangsu Mei Lian Information Technology Co., Ltd.", numwidth,numhright+280); */            /*num + = 50;            Font font2=new font ("Song Body", Font.plain, 40);            G.setfont (Font2);            G.setpaint (Color.dark_gray);             g.DrawString ("Origin:", Numwidth, Numhright+num);              num + = 50; g.DrawString ("Delivery Method:", Numwidth, numhright+num);*/G.dispose (); Imageio.write (BufferedImage2,"JPG",NewFile ("e:/20170429/2017410 backup/testimage/4.jpg")); } Catch(Exception e) {e.printstacktrace (); }        }         Public Static Final voidMain (string[] args) {overlapimage ("E:/20170429/2017410 backup/testimage/bg.png", "e:/20170429/2017410 backup/testimage/2.png", "e:/20170429/2017410 backup/ Testimage/2.png "); }      }

JAVA------20. Inserting text and pictures in a picture

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.