Java Utililty Methods Image Resize

List of utility methods to do Image Resize

Description

The list of methods to do Image Resize are organized into topic(s).

Method

voidresizeImage(String loadFile, String saveFile, int maxDim)
resize Image
File save = new File(saveFile.replaceAll("/", "\\" + File.separator));
FileInputStream fis = new FileInputStream(loadFile.replaceAll("/", "\\" + File.separator));
BufferedImage im = ImageIO.read(fis);
Image inImage = new ImageIcon(loadFile).getImage();
double scale = (double) maxDim / (double) inImage.getHeight(null);
if (inImage.getWidth(null) > inImage.getHeight(null)) {
    scale = (double) maxDim / (double) inImage.getWidth(null);
int scaledW = (int) (scale * inImage.getWidth(null));
int scaledH = (int) (scale * inImage.getHeight(null));
BufferedImage thumb = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = thumb.createGraphics();
g2.drawImage(im, 0, 0, scaledW, scaledH, null);
ImageIO.write(thumb, "jpg", save);