Кода -копия выглядит следующим образом:
Public Class Picture {
// Todo Auto Generated Constructor Stub
public static void relesizepng (String fromfile, String tofile, int outputwidth, int outputheight, логическая пропорция) {
пытаться {
Файл F2 = новый файл (отфиль);
BufferedImage bi2 = imageio.read (f2);
int newwidth;
int newheight;
// определить, является ли это соотношение масштабирования
if (proportion == true) {
// Рассчитать ширину и высоту выходного изображения для масштабирования равного соотношения
двойная скорость1 = ((двойной) bi2.getwidth (null)) / (двойная) выходная Whith + 0,1;
двойная скорость2 = ((двойной) bi2.getheight (null)) / (Double) Outputheight + 0,1;
// Управление масштабированием в соответствии с большим соотношением масштабирования
Двойная скорость = скорость1 <скорость 2?
newWidth = (int) ((((двойной) bi2.getWidth (null)) / скорость);
newheight = (int) ((((двойной) bi2.getheight (null)) / скорость);
} еще {
newwidth = outputwidth;
Newheight = Outputheight;
}
BufferedImage to = new BufferedImage (NewWidth, Newheight,
BufferedImage.type_int_rgb);
Graphics2d g2d = to.creategraphics ();
to = g2d.getDeviceConfiguration (). CreateCompatibleImage (NewWidth, Newheight,
Прозрачность. Транслюкентный);
G2D.Dispose ();
g2d = to.creategraphics ();
Изображение из = bi2.getscaledInstance (NewWidth, Newheight, BI2.Scale_area_Averaging);
g2d.drawimage (от, 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 ("start");
RESIZEPNG ("C: // документы и настройки // Администратор // Desktop // 8D9E9C82D158CCBF8B31059319D8BC3EB035414E.JPG", "C: // Documents and Settings // Администратор // Desktop // ell.png" ;
System.out.println ("OK");
}
}