Exemplos são os seguintes:
pacote writeImg; importar javax.imageio.imageio; importar java.awt.color; importar java.awt.font; importar java.awt.graphics2d; importar java.awt.image.bufferiMage; importar java.io.file; importar java.io.ioException; importar java.net.url; public classe pic {fonte privada Fonte = new Font ("Huawen Caiyun", font.plain, 40); // Adicione propriedades da fonte para definir gráficos privados 2d g = null; private int fontSize = 0; privado int x = 0; private int y = 0; / *** importar imagem local para buffer*/ public bufferImage loadImagelocal (string imggname) {try {return imageio.read (new File (iMgname)); } catch (ioexception e) {System.out.println (e.getMessage ()); } retornar nulo; } / *** Importar imagem de rede para buffer* / public bufferImage loadImageurl (string imggname) {try {url url = new url (imggname); retornar imageio.read (URL); } catch (ioexception e) {System.out.println (e.getMessage ()); } retornar nulo; } / *** Gere uma nova imagem para o local* / public void writeImagelocal (string newImage, bufferImage img) {if (newImage! = Null && img! = Null) {try {file outputfile = new File (newImage); Imageio.write (img, "jpg", saída de saída); } catch (ioexception e) {System.out.println (e.getMessage ()); }}}} / *** Defina a fonte, etc. do texto* / public void setFont (string fontStyle, int fontSize) {this.fontsize = fontSize; this.font = nova fonte (fontstyle, font.plain, fontsize); } / ** * Modifique a figura e retorne o buffer de imagem modificado (apenas uma linha de texto) * / public bufferImage modifyImage (bufferImage img, conteúdo do objeto, int x, int y) {try {int w = img.getwidth (); int h = img.getHeight (); g = img.creategraphics (); g.setbackground (cor.white); g.setColor (color.orange); // Defina a cor da fonte if (this.font! = null) g.setFont (this.font); // Verifique as coordenadas ordenadas e horizontais da posição de saída se (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 (Exceção e) {System.out.println (e.getMessage ()); } retornar img; } /*** Modifique a figura e retorne o buffer de imagem modificado (saída de vários segmentos de texto) Xory: true significa produzir o conteúdo em uma linha; false significa saída o conteúdo várias linhas*/ public bufferImage modifyImage (bufferImage img, object [] contentarr, int x, int y, boolean xory) {try {int w = img.getwidth (); int h = img.getHeight (); g = img.creategraphics (); g.setbackground (cor.white); g.setColor (color.red); if (this.font! = null) g.setFont (this.font); // Verifique as coordenadas ordenadas e horizontais da posição de saída se (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 (). length () * this.fontSize/ 2 +5; // recalcula a posição de saída de texto}} else {for (int i = 0; i <arrlen; i ++) {g.drawstring (contentarr [i] .tostring (), this.x, this.x; this.y + = this.fontSize + 2; // recalcula a posição de saída de texto}}} g.dispose (); } catch (Exceção e) {System.out.println (e.getMessage ()); } retornar img; } / ** * Modifique a figura e retorne o buffer de imagem modificado (apenas uma linha de texto) * * Horário: 2007-10-8 * * @param img * @return * / public bufferImage modifyImageye (bufferiMage img) {try {int w = img.getwidth (); int h = img.getHeight (); g = img.creategraphics (); g.setbackground (cor.white); g.setColor (color.blue); // Defina a cor da fonte if (this.font! = null) g.setFont (this.font); G.DrawString ("Reyo.cn", W - 85, H - 5); G.Dispose (); } catch (Exceção e) {System.out.println (e.getMessage ()); } retornar img; } public bufferImage modifyImageTogeter (bufferImage b, bufferImage d) {try {int w = b.getwidth (); int h = B.GetHeight (); g = D.Creategraphics (); G.Drawimage (B, 100, 10, W, H, Null); G.Dispose (); } catch (Exceção e) {System.out.println (e.getMessage ()); } retornar d; } public static void main (string [] args) {pic tt = new pic (); BufferImage d = tt.loadimagelocal ("d: //11.jpg"); // bufferImage b = tt // .loadImagelocal ("e: // arquivo (word, Excel, pdf, ppt.txt) // zte-logo.png"); tt.WriteImagelocal ("d: //cc.jpg", tt.modifyImage (D, "Xichang Apple", 90,90) // Escreva um arquivo na foto); //tt.writeimagelocal("d://cc.jpg ", tt.modifyImageTogeter (b, d)); // agrupe várias imagens juntos System.out.println ("Sucesso"); }}O exposto acima é o conteúdo completo da escrita de java nas imagens e as duas imagens que mesciam métodos. Espero que todos apoiem mais wulin.com ~