This commit is contained in:
looly 2021-12-17 18:04:59 +08:00
parent 8c7106d7f3
commit 1756535595
3 changed files with 16 additions and 8 deletions

View File

@ -10,6 +10,7 @@
* 【core 】 新增DatePattern.createFormatterpr#483@Gitee
* 【core 】 增加IdUtil.getSnowflakeNextIdpr#485@Gitee
* 【log 】 log4j2的编译依赖改为apicore为test依赖pr#2019@Github
* 【core 】 Img.scale缩小默认使用平滑模式issue#I4MY6X@Gitee
*
### 🐞Bug修复
* 【core 】 LineReadWatcher#onModify文件清空判断问题issue#2013@Github

View File

@ -253,23 +253,30 @@ public class Img implements Serializable {
* @return this
*/
public Img scale(int width, int height) {
return scale(width, height, Image.SCALE_SMOOTH);
}
/**
* 缩放图像按长宽缩放<br>
* 注意目标长宽与原图不成比例会变形
*
* @param width 目标宽度
* @param height 目标高度
* @param scaleType 缩放类型可选{@link Image#SCALE_SMOOTH}平滑模式或{@link Image#SCALE_DEFAULT}默认模式
* @return this
* @since 5.7.18
*/
public Img scale(int width, int height, int scaleType) {
final Image srcImg = getValidSrcImg();
int srcHeight = srcImg.getHeight(null);
int srcWidth = srcImg.getWidth(null);
int scaleType;
if (srcHeight == height && srcWidth == width) {
// 源与目标长宽一致返回原图
this.targetImage = srcImg;
return this;
} else if (srcHeight < height || srcWidth < width) {
// 放大图片使用平滑模式
scaleType = Image.SCALE_SMOOTH;
} else {
scaleType = Image.SCALE_DEFAULT;
}
if (ImgUtil.IMAGE_TYPE_PNG.equals(this.targetImageType)) {
// png特殊处理借助AffineTransform可以实现透明度保留
final double sx = NumberUtil.div(width, srcWidth);// 宽度缩放比

View File

@ -207,7 +207,7 @@ public class StyleUtil {
* 创建数据格式并获取格式
*
* @param workbook {@link Workbook}
* @param format 数据格式
* @param format 数据格式
* @return 数据格式
* @since 5.5.5
*/