A cópia do código é a seguinte:
classe pública imagem {
// TODO Construtor GOERATADO AUTO ESTUB
public static void resizepng (string fromfile, string tofile, int OutputWidth, int Outputhight, proporção booleana) {
tentar {
Arquivo f2 = novo arquivo (do arquivo);
BufferImage bi2 = imageio.read (f2);
int newwidth;
int newHeight;
// determinar se é uma taxa de escala
if (proporção == true) {
// Calcule a largura e a altura da imagem de saída para escala igual
Taxa dupla 1 = ((dupla) bi2.getwidth (nulo)) / (duplo) outwidth + 0,1;
Taxa dupla 2 = ((duplo) bi2.getheight (nulo)) / (duplo) Outputhight + 0,1;
// Controle de escala de acordo com a grande taxa de escala
Taxa dupla = Taxa 1 <taxa2?
newwidth = (int) ((((duplo) bi2.getwidth (null)) / taxa);
newHeight = (int) ((((duplo) bi2.getheight (nulo)) / taxa);
} outro {
newwidth = outputWidth;
newHeight = Outputhight;
}
BufferImage para = new bufferImage (Newwidth, NewHeight,
BufferImage.type_int_rgb);
Graphics2d g2d = to.creategraphics ();
para = g2d.getDeviceConfiguration (). CreateCompatibleImage (Newwidth, NewHeight,
Transparência.Translucent);
g2d.dispose ();
g2d = to.creategraphics ();
Imagem de = bi2.getScaledInstance (Newwidth, newHeight, bi2.scale_area_averraging);
g2d.Drawimage (de, 0, 0, nulo);
g2d.dispose ();
Imageio.write (para, "png", novo arquivo (tofile));
} catch (ioexception e) {
E.PrintStackTrace ();
}
}
public static void main (string [] args) lança ioexception {
System.out.println ("start");
Resizepng ("C: // Documentos e Configurações // Administrador // Desktop // 8D9E9C82D158CCBF8B31059319D8BC3EB035414E.JPG", "C: // Documentos, // Administrador // Desktop //10 ;
System.out.println ("ok");
}
}