코드 사본은 다음과 같습니다.
공개 수업 사진 {
// TODO 자동 생성 생성자 스텁
public static void resizepng (문자열 Fromfile, String tofile, int outputwidth, int outputheight, 부울 비율) {
노력하다 {
파일 f2 = 새 파일 (Fromfile);
BufferedImage bi2 = imageio.read (f2);
int newwidth;
int NewHeight;
// 스케일링 비율 여부를 결정합니다
if (prosation == true) {
// 동일한 비율 스케일링에 대한 출력 이미지 너비 및 높이 계산
이중 속도 1 = ((이중) bi2.getWidth (null)) / (double) outputWidth + 0.1;
이중 속도 2 = ((이중) bi2.getheight (null)) / (double) outputheight + 0.1;
// 대규모 스케일링 비율에 따라 제어를 스케일링합니다
이중 속도 = rate1 <rate2 : rate2;
newwidth = (int) (((((()) bi2.getWidth (null))) / rate);
newHeight = (int) (((((()) bi2.getheight (null))) / rate);
} 또 다른 {
Newwidth = outputwidth; // 출력 이미지 너비
NewHeight = OutPutheight; // 출력 이미지 높이
}
BufferedImage to = New BufferedImage (Newwidth, NewHeight,
bufferedImage.type_int_rgb);
그래픽 2d g2d = to.creategraphics ();
to = g2d.getDeviceConfiguration (). CreateCompatibleImage (Newwidth, NewHeight,
투명성. 외투);
g2d.dispose ();
g2d = to.creategraphics ();
image from = bi2.getScaledInstance (Newwidth, NewHeight, bi2.scale_area_averaging);
G2D.DrawImage (From, 0, 0, NULL);
g2d.dispose ();
imageio.write (to, "png", 새 파일 (tofile));
} catch (ioexception e) {
e.printstacktrace ();
}
}
public static void main (String [] args)은 ioexception {
System.out.println ( "시작");
resizepng ( "C : // 문서 및 설정 // 관리자 // desktop // 8d9e9c82d158ccbf8b31059319d8bc3eb035414e.jpg", "c : // documents and settome // vactiontop // elel.png", 200, 100, true " ;
System.out.println ( "OK");
}
}