时间:2018-11-09
概述:图片缩放
本教程主要介绍两个Java函数,用于完成Java对指定宽度的网络图片、本地图片的按比例缩放功能,下面分开来说明两个代码:
1、Java按照固定宽度进行等比缩放本地图片,以下是参数说明:
@param width 固定宽度
@param savePath 保存路径、名称
@param targetFile 本地目标文件
@return 返回保存路径
@throws ImageFormatException
@throws IOException
以下是函数代码:
public static String resize(int width, String savePath, File targetFile) throws ImageFormatException, IOException {
image = ImageIO.read(targetFile);
int[] size = getSize(width, image);
return resize(size[0], size[1], savePath, image);
}
2、Java按照固定宽度进行等比缩放网络图片,以下是参数说明:
@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);
}
最后
以上就是优美时光最近收集整理的关于java 图片长宽缩放_Java按固定宽度等比例放大缩放本地和网络图片的全部内容,更多相关java内容请搜索靠谱客的其他文章。
发表评论 取消回复