Here you can find the source of makeImageResizer(String srcImgPath, String targerPath, int scaledWidth, int scaledHeight, boolean preserveAlpha)
public static void makeImageResizer(String srcImgPath, String targerPath, int scaledWidth, int scaledHeight, boolean preserveAlpha) throws IOException
//package com.java2s; //License from project: Apache License import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public class Main { public static void makeImageResizer(String srcImgPath, String targerPath, int scaledWidth, int scaledHeight, boolean preserveAlpha) throws IOException { BufferedImage originalImage = ImageIO.read(new File(srcImgPath)); int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, imageType); Graphics2D g = scaledBI.createGraphics(); if (preserveAlpha) { g.setComposite(AlphaComposite.Src); }/*w w w . j av a 2 s .c o m*/ g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null); g.dispose(); ImageIO.write(scaledBI, getImageFileSuffix(srcImgPath), new File(targerPath)); } public static String getImageFileSuffix(String imagePath) { String imageSuffix = "jpg"; int index = imagePath.lastIndexOf("."); if (index > -1) { imageSuffix = imagePath.substring(index + 1); } return imageSuffix; } }