예는 다음과 같습니다.
패키지 writeimg; import javax.imageio.imageio; import java.awt.color; Java.awt.Font 가져 오기; import java.awt.graphics2d; java.awt.image.bufferedimage import; import java.io.file; import java.io.ioexception; import java.net.url; 공개 클래스 PIC {private font font = new Font ( "Huawen Caiyun", font.plain, 40); // 프라이빗 그래픽을 설정하기 위해 글꼴 속성을 추가합니다 2d g = null; 개인 int fontsize = 0; 개인 int x = 0; 개인 int y = 0; / *** 로컬 이미지를 버퍼로 가져옵니다*/ public bufferedImage loadImagelocal (String imgname) {try {return imageio.read (새 파일 (imgname)); } catch (ioException e) {System.out.println (e.getMessage ()); } return null; } / *** 버퍼로 네트워크 이미지 가져 오기* / 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; } / *** 로컬* / public void writeImagelocal (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 ()); }}}} / *** 텍스트의 글꼴 등을 설정* / public void setfont (String fontstyle, int fontsize) {this.fontsize = fontsize; this.font = new Font (fontstyle, font.plain, fontsize); } / ** * 그림을 수정하고 수정 된 이미지 버퍼 (한 줄의 텍스트 출력) * / public bufferedImage modifyImage (bufferedImage img, 객체 내용, int x, int y) {try {int w = img.getWidth (); int h = img.getheight (); g = img.creategraphics (); G. 세트 백 그라운드 (Color.white); g.setcolor (color.orange); // 글꼴 색상을 If (this.font! = null) G.setfont (this.font); // (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 (예외 e) {system.out.println (e.getMessage ()); } return img; } /*** 그림을 수정하고 수정 된 이미지 버퍼 (출력 다중 텍스트 세그먼트) Xory : True는 한 줄에서 내용을 출력합니다. 거짓은 여러 줄에서 내용을 출력*/ 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. 세트 백 그라운드 (Color.white); g.setcolor (color.red); if (this.ont! = null) g.setfont (this.font); // (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; // 텍스트 출력 위치를 다시 계산}} else {for (int i = 0; i <arrlen; i ++) {G.DrawString (contentArr [i] .toString (this.x, this.y); this.y + = this.fontsize + 2; // 텍스트 출력 위치}}} g.dispose (); } catch (예외 e) {system.out.println (e.getMessage ()); } return img; } / ** * 그림을 수정하고 수정 된 이미지 버퍼를 반환합니다 (한 줄의 텍스트 만 출력) * * 시간 : 2007-10-8 * * @param img * / public bufferedImage modifyImageye (bufferedImage img) {try {int w = img.getWidth (); int h = img.getheight (); g = img.creategraphics (); G. 세트 백 그라운드 (Color.white); g.setcolor (color.blue); // 글꼴 색상을 If (this.font! = null) G.setfont (this.font); G.DrawString ( "Reyo.cn", W -85, H -5); g.dispose (); } catch (예외 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.dispose (); } catch (예외 e) {system.out.println (e.getMessage ()); } 반환 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) // 사진에 파일을 작성); //tt.writeimagelocal("d://cc.jpg ", tt.modifyimagetogeter (b, d)); // 여러 그림을 함께 그룹화 System.out.println ( "성공"); }}위는 사진에 대한 Java의 전체 내용과 두 개의 그림 합병 방법입니다. 모두가 wulin.com을 더 지원하기를 바랍니다