Los ejemplos son los siguientes:
paquete WriteImg; import javax.imageio.imageio; import java.awt.color; import java.awt.font; import java.awt.graphics2d; import java.awt.image.bufferedImage; import java.io.file; import java.io.ioException; import java.net.url; Public Class Pic {private font font = new Font ("Huawen Caiyun", font.plain, 40); // Agregar propiedades de fuentes para establecer gráficos privados2d g = null; privado int fontSize = 0; private int x = 0; private int y = 0; / *** Importar imagen local a buffer*/ public BufferedImage LoadImageLocal (String imgname) {try {return imageIO.Read (nuevo archivo (imgname)); } catch (ioException e) {System.out.println (E.GetMessage ()); } return null; } / *** Importar imagen de red a buffer* / public BufferedImage LoadImageUrl (string imgname) {try {url url = new url (imgname); return ImageIO.Read (URL); } catch (ioException e) {System.out.println (E.GetMessage ()); } return null; } / *** Genere una nueva imagen al local* / public void WriteMageLocal (String NewImage, BufferedImage img) {if (NewImage! = NULL && img! = NULL) {try {File outputFile = new File (NewImage); ImageIO.Write (img, "jpg", outputFile); } catch (ioException e) {System.out.println (E.GetMessage ()); }}}} / *** Establezca la fuente, etc. del texto* / public void setFont (string fontstyle, int fontSize) {this.fontSize = fontSize; this.font = new Font (FontStyle, Font.Plain, FontSize); } / ** * Modifique la imagen y devuelva el búfer de imagen modificado (solo emita una línea de texto) * / public BufferedImage ModifyImage (BufferedImage IMG, Object Content, Int X, Int y) {try {int w = img.getWidth (); int h = img.getheight (); g = img.createGraphics (); G.SetBackground (color.white); G.SetColor (color.orange); // Establezca el color de la fuente if (this.font! = null) g.setFont (this.font); // Verifique las coordenadas de ordenadas y horizontales de la posición de salida si (x> = h || y> = w) {this.x = h - this.fontSize + 2; this.y = w; } else {this.x = x; this.y = y; } if (content! = null) {g.drawstring (content.toString (), this.x, this.y); } G.Dispose (); } catch (Exception e) {System.out.println (e.getMessage ()); } return img; } /*** Modifique la imagen y devuelva el búfer de imagen modificado (salida de múltiples segmentos de texto) Xory: Verdadero medios de salida el contenido en una línea; False significa generar el contenido múltiples líneas*/ public bufferedImage ModifyImage (BufferedImage img, object [] contentarr, int x, int y, boolean xory) {try {int w = img.getwidth (); int h = img.getheight (); g = img.createGraphics (); G.SetBackground (color.white); G.SetColor (Color.Red); if (this.font! = null) g.setFont (this.font); // Verifique las coordenadas de ordenadas y horizontales de la posición de salida si (x> = h || y> = w) {this.x = h - this.fontSize + 2; this.y = w; } else {this.x = x; this.y = y; } if (contentarr! = null) {int arrlen = contentarr.length; if (xory) {for (int i = 0; i <arrlen; i ++) {g.drawstring (contentarr [i] .ToString (), this.x, this.y); this.x += Contentarr [i] .ToString (). Longitud () * this.fontSize/ 2 +5; // Recalcule la posición de salida del texto}} else {for (int i = 0; i <arrlen; i ++) {g.drawstring (contentARR [i] .Tostring (), this.x, this.y); this.y + = this.fontSize + 2; // recalcular la posición de salida del texto}}} g.dispose (); } catch (Exception e) {System.out.println (e.getMessage ()); } return img; } / ** * Modifique la imagen y devuelva el búfer de imagen modificado (solo emita una línea de texto) * * Tiempo: 2007-10-8 * * @param img * @return * / public bufferedImage ModifyImageye (bufferedimage img) {try {int w = img.getWidth (); int h = img.getheight (); g = img.createGraphics (); G.SetBackground (color.white); G.SetColor (color.blue); // Establezca el color de la fuente if (this.font! = null) g.setFont (this.font); G.DrawString ("Reyo.cn", W - 85, H - 5); G.Dispose (); } catch (Exception e) {System.out.println (e.getMessage ()); } return img; } public BufferedImage ModifyImageTogeter (BufferedImage B, BufferedImage D) {try {int w = B.getWidth (); int h = b.getheight (); g = d.createGraphics (); G.Drawimage (b, 100, 10, W, H, nulo); G.Dispose (); } catch (Exception e) {System.out.println (e.getMessage ()); } retorno d; } public static void main (string [] args) {pic tt = new Pic (); BufferedImage d = tt.loadImageLocal ("d: //11.jpg"); // BufferedImage b = tt // .LoadImageLocal ("e: // file (word, Excel, pdf, ppt.txt) // zte-logo.png"); TT.WriteImageLocal ("D: //cc.jpg", tt.modifyImage (d, "xichang Apple", 90,90) // escribe un archivo en la imagen); //tt.WriteImagelocal("d://cc.jpg ", tt.modifyimageTogeter (b, d)); // agrupar múltiples imágenes juntas System.out.println ("éxito"); }}Lo anterior es el contenido completo de la escritura de Java en imágenes y las dos imágenes de métodos de fusión. Espero que todos apoyen a Wulin.com más ~