mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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);// 宽度缩放比
|
||||
|
Reference in New Issue
Block a user