我是靠谱客的博主 优美时光,这篇文章主要介绍java 图片长宽缩放_Java按固定宽度等比例放大缩放本地和网络图片,现在分享给大家,希望可以做个参考。

时间: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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部