int targetWidth = image.getWidth(null);
int targetHeight = image.getHeight(null);
long height = Math.round((targetHeight * width) / (targetWidth * 1.00f));
return new int[] { width, Integer.parseInt(String.valueOf(height)) };
}
public static int[] getSizeByHeight(int height, Image image) {
int targetWidth = image.getWidth(null);
int targetHeight = image.getHeight(null);
long width = Math.round((targetWidth * height) / (targetHeight * 1.00f));
return new int[] { Integer.parseInt(String.valueOf(width)), height };
}
/**
*
* function: 将指定的targetFile图片文件的宽度、高度大于指定width、height的图片缩小,并保存在savePath目录
* @author hoojo
* @createDate 2012-2-6 下午04:57:02
* @param width 缩小的宽度
* @param height 缩小的高度
* @param savePath 保存目录
* @param targetImage 改变的目标图片
* @return 图片保存路径、名称
* @throws ImageFormatException
* @throws IOException
*/
public static String resize(int width, int height, String savePath, File targetFile) throws ImageFormatException, IOException {
image = ImageIO.read(targetFile);
int[] size = getSize(width, height, image);
return resize(size[0], size[1], savePath, image);
}
/**
*
* function: 将指定的targetURL网络图片文件的宽度、高度大于指定width、height的图片缩小,并保存在savePath目录
* @author hoojo
* @createDate 2012-2-6 下午04:57:07
* @param width 缩小的宽度
* @param height 缩小的高度
* @param savePath 保存目录
* @param targetImage 改变的目标图片
* @return 图片保存路径、名称
* @throws ImageFormatException
* @throws IOException
*/
public static String resize(int width, int height, String savePath, URL targetURL) throws ImageFormatException, IOException {
image = ImageIO.read(targetURL);
int[] size = getSize(width, height, image);
}
/**
* function: 将一个本地的图片文件按照指定的比例进行缩放
* @author hoojo
* @createDate 2012-2-7 上午10:29:18
* @param scale 缩放比例
* @param savePath 保存文件路径、名称
* @param targetFile 本地图片文件
* @return 新的文件名称
* @throws ImageFormatException
* @throws IOException
*/
public static String resize(float scale, String savePath, File targetFile) throws ImageFormatException, IOException {
image = ImageIO.read(targetFile);
int[] size = getSize(scale, image);
return resize(size[0], size[1], savePath, image);
}
/**
* function: 将一个网络图片文件按照指定的比例进行缩放
* @author hoojo
* @createDate 2012-2-7 上午10:30:56
* @param scale 缩放比例
* @param savePath 保存文件路径、名称
* @param targetFile 本地图片文件
* @return 新的文件名称
* @throws ImageFormatException
* @throws IOException
*/
public static String resize(float scale, String savePath, URL targetURL) throws ImageFormatException, IOException {
image = ImageIO.read(targetURL);
int[] size = getSize(scale, image);
return resize(size[0], size[1], savePath, image);
}
/**
* function: 按照固定宽度进行等比缩放本地图片
* @author hoojo
* @createDate 2012-2-7 上午10:49:56
* @param width 固定宽度
* @param savePath 保存路径、名称
* @param targetFile 本地目标文件
* @return 返回保存路径
* @throws ImageFormatException
* @throws IOException
*/
public static String resize(int width, String savePath, File targetFile) throws ImageF