Beispiele sind wie folgt:
Paketschreibungen; import Javax.imageo.imageo; Import Java.awt.Color; import Java.awt.font; Import Java.awt.Graphics2d; Import Java.awt.image.BuffenedImage; Import Java.io.file; importieren java.io.ioException; importieren java.net.url; public class pic {private font font = new font ("huawen caiyun", font.plain, 40); // font -Eigenschaften hinzufügen, um private graphics2d g = null zu setzen; private int fontsize = 0; private int x = 0; private int y = 0; / *** Lokales Bild in Buffer importieren*/ public bufferedImage loadImagelocal (String imgname) {try {return imageio.read (neue Datei (IMGName)); } catch (ioException e) {System.out.println (e.getMessage ()); } return null; } / *** Netzwerkbild in Buffer importieren* / 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; } / *** generieren Sie ein neues Bild für die lokalen* / public void Recordelocal (String NewImage, BufferedImage img) {if (newImage! = Null && img! Imageio.Write (IMG, "JPG", OutputFile); } catch (ioException e) {System.out.println (e.getMessage ()); }}}} / *** Setzen Sie die Schriftart usw. des Textes* / public void setfont (String fontStyle, int fontSize) {this.fontSize = fontSize; this.font = new font (fontStyle, font.plain, fontsize); } / ** * das Bild ändern und den geänderten Bildpuffer zurückgeben (nur eine Textzeile ausgeben) * / public bufferedImage modifyImage (bufferedImage IMG, Objektinhalt, int x, int y) {try {int w = img.getwidth (); int h = img.getheight (); g = img.createGraphics (); G.Setbackground (color.white); G.SetColor (color.orange); // Setzen Sie die Schriftfarbe if (this.font! = null) g.setfont (this.font); // Überprüfen Sie die Ordinate und die horizontalen Koordinaten der Ausgangsposition if (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.disponse (); } catch (Ausnahme e) {System.out.println (e.getMessage ()); } return img; } /*** das Bild ändern und den geänderten Bildpuffer zurückgeben (Ausgabe mehrerer Textsegmente) XORY: TRUE MEISE FÜR DEN Inhalt in einer Zeile ausgeben. false bedeutet, die Inhalt mehrere Zeilen auszugeben int h = img.getheight (); g = img.createGraphics (); G.Setbackground (color.white); G.SetColor (color.red); if (this.font! = null) g.setfont (this.font); // Überprüfen Sie die Ordinate und die horizontalen Koordinaten der Ausgangsposition if (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) {für (int i = 0; i <arrlen; i ++) {g.drawstring (contentarr [i] .ToString (), this.x, this.y); this.x += contentarr [i] .ToString (). Länge () * this.fontSize/ 2 +5; // Die Textausgabeposition}} else {für (int i = 0; i <arrlen; i ++) {g.drawstring (contentarr [i] .ToString (), this.x, this.y); this.y + = this.fontSize + 2; // Die Textausgabeposition}}} g.dispose () neu berechnen; } catch (Ausnahme e) {System.out.println (e.getMessage ()); } return img; } / ** * das Bild ändern und den geänderten Bildpuffer zurückgeben (nur eine Textzeile ausgeben) * * Zeit: 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); // Setzen Sie die Schriftfarbe if (this.font! = null) g.setfont (this.font); g.drawstring ("reyo.cn", w - 85, h - 5); g.disponse (); } catch (Ausnahme 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, Null); g.disponse (); } catch (Ausnahme e) {System.out.println (e.getMessage ()); } return d; } public static void main (String [] args) {pic tt = new pic (); Bufferedimage d = tt.loadImagelocal ("d: //11.jpg"); // bufferedImage b = tt // .loadImagelocal ("e: // Datei (Wort, Excel, pdf, ppt.txt) // Zte-logo.png"); tt.writeImagelocal ("d: //cc.jpg", tt.modifyImage (d, "Xichang Apple", 90,90) // eine Datei auf das Bild schreiben); //tt.writeImagelocal("d://cc.jpg ", tt.modifyImagetogeter (b, d)); // Mehrere Bilder zusammengruppen system.out.println ("Erfolg"); }}Das obige ist der vollständige Inhalt des Java -Schreibens auf Bildern und den beiden Zusammenführungsmethoden. Ich hoffe, jeder wird Wulin.com mehr unterstützen ~