缩放图片工具类,创建缩略图、伸缩图片比例 (四)

2014-11-24 07:11:56 · 作者: · 浏览: 2
ormatException, IOException {
image = ImageIO.read(targetFile);
int[] size = getSize(width, image);
return resize(size[0], size[1], savePath, image);
}

/**
* function: 按照固定宽度进行等比缩放网络图片
* @author hoojo
* @createDate 2012-2-7 上午10:50:52
* @param width 固定宽度
* @param savePath 保存路径、名称
* @param targetFile 本地目标文件
* @return 返回保存路径
* @throws ImageFormatException
* @throws IOException
*/
public static String resize(int width, String savePath, URL targetURL) throws ImageFormatException, IOException {
image = ImageIO.read(targetURL);
int[] size = getSize(width, image);
return resize(size[0], size[1], savePath, image);
}

/**
*
* function: 按照固定高度进行等比缩放本地图片
* @author hoojo
* @createDate 2012-2-7 上午10:51:17
* @param height 固定高度
* @param savePath 保存路径、名称
* @param targetFile 本地目标文件
* @return 返回保存路径
* @throws ImageFormatException
* @throws IOException
*/
public static String resizeByHeight(int height, String savePath, File targetFile) throws ImageFormatException, IOException {
image = ImageIO.read(targetFile);
int[] size = getSizeByHeight(height, image);
return resize(size[0], size[1], savePath, image);
}

/**
* function: 按照固定高度进行等比缩放网络图片
* @author hoojo
* @createDate 2012-2-7 上午10:52:23
* @param height 固定高度
* @param savePath 保存路径、名称
* @param targetFile 本地目标文件
* @return 返回保存路径
* @throws ImageFormatException
* @throws IOException
*/
public static String resizeByHeight(int height, String savePath, URL targetURL) throws ImageFormatException, IOException {
image = ImageIO.read(targetURL);
int[] size = getSizeByHeight(height, image);
return resize(size[0], size[1], savePath, image);
}

/**
* function:
* @author hoojo
* @createDate 2012-2-3 上午10:08:47
* @param args
* @throws IOException
* @throws MalformedURLException
* @throws ImageFormatException
*/
public static void main(String[] args) throws ImageFormatException, MalformedURLException, IOException {

System.out.println(ScaleImageUtils.resize(140, 140, null, new URL("https://www.cppentry.com/upload_files/article/76/1_n3v3h__.jpg")));
ScaleImageUtils.resize(100, 100, ImageQuality.high.getQuality(), null, ImageIO.read(new URL("https://www.cppentry.com/upload_files/article/76/1_n3v3h__.jpg")));
}
}


作者:hoojo