How to write in the picture

xiaoxiao2021-03-06  15

Let's find a picture before the start, and name it Kobe.jpg to the root directory

Import java.awt.color; import java.awt.font; import java.awt.graphchics2d; import java.awt.image.bufferedimage; import java.io.fileinputstream; import java.io.fileoutputstream;

Import javax.imageio.imageio;

Import com.sun.image.codec.jpeg.jpegcodec; import com.sun.image.codec.jpeg.jpegimageEncoder;

public class ImageDraw {public static void main (String [] args) {try {// read the contents of the template image BufferedImage image = ImageIO.read (new FileInputStream ( "kobe.JPG")); Graphics2D g = image.createGraphics () ; // Get graphical context g.SetColor (color.White); // Set the brush color // set font G.SetFont (New Font ("GIGI", 3, 60)); // Write Signature // below 43 in one sentence ().getHeight () - 10 can be changed to the coordinates you want. g.drawstring ("FUN2008@126.com", Image.GetWidth () / 9, Image.getHeight () / 2); g.dispose (); fileoutputstream out = new fileoutputstream ("kobe.jpg"); JPEGIMAGEENCODER ENCODER = JPEGCODEC.CREATEJPEGENCODER (OUT); Encoder.Encode (Image); out.close ();} catch (exception e) {E.PrintStackTrace ();}

}

转载请注明原文地址:https://www.9cbs.com/read-46074.html

New Post(0)