From f2929518ad371019913e4ee584f2eaa12f1bc073 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Wed, 9 Oct 2019 17:38:38 +0800 Subject: [PATCH] =?UTF-8?q?MOBILE-23325=20=E3=80=90=E5=8D=95=E9=80=89?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=A0=B7=E5=BC=8F=E3=80=91=E5=9B=BE=E6=96=87?= =?UTF-8?q?=E6=8C=89=E9=92=AE=EF=BC=9A=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E7=A7=BB=E5=8A=A8=E7=AB=AF=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BE=88=E6=A8=A1=E7=B3=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/utils/ImageUtils.java | 19 +++++++++++-------- .../com/fr/design/web/CustomIconPane.java | 13 +++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/utils/ImageUtils.java b/designer-base/src/main/java/com/fr/design/utils/ImageUtils.java index 389b9981e..7bd2d406e 100644 --- a/designer-base/src/main/java/com/fr/design/utils/ImageUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/ImageUtils.java @@ -240,6 +240,7 @@ public class ImageUtils { * @param opacityCompatible 是否处理背景透明 */ public static BufferedImage scale(BufferedImage srcImg, float scale, boolean opacityCompatible) { + int scaleType; if (scale < 0) { // 自动修正负数 scale = -scale; @@ -247,7 +248,15 @@ public class ImageUtils { int width = mul(Integer.toString(srcImg.getWidth(null)), Float.toString(scale)).intValue(); // 得到源图宽 int height = mul(Integer.toString(srcImg.getHeight(null)), Float.toString(scale)).intValue(); // 得到源图长 - return CoreGraphHelper.toBufferedImage(scale(srcImg, width, height, opacityCompatible)); + int srcHeight = srcImg.getHeight(null); + int srcWidth = srcImg.getWidth(null); + if (srcHeight < height || srcWidth < width) { + // 放大图片使用平滑模式 + scaleType = Image.SCALE_SMOOTH; + } else { + scaleType = Image.SCALE_DEFAULT; + } + return CoreGraphHelper.toBufferedImage(scale(srcImg, width, height, opacityCompatible, scaleType)); } private static BigDecimal mul(String v1, String v2) { @@ -268,18 +277,12 @@ public class ImageUtils { * @param opacityCompatible 是否处理背景透明 * @return {@link Image} */ - private static Image scale(BufferedImage srcImg, int width, int height, boolean opacityCompatible) { + public static Image scale(BufferedImage srcImg, int width, int height, boolean opacityCompatible, int scaleType) { int srcHeight = srcImg.getHeight(null); int srcWidth = srcImg.getWidth(null); - int scaleType; if (srcHeight == height && srcWidth == width) { // 源与目标长宽一致返回原图 return srcImg; - } else if (srcHeight < height || srcWidth < width) { - // 放大图片使用平滑模式 - scaleType = Image.SCALE_SMOOTH; - } else { - scaleType = Image.SCALE_DEFAULT; } if (opacityCompatible) {//需要保留透明度背景 BufferedImage toImg = CoreGraphHelper.createBufferedImage(width, height, srcImg.getType()); diff --git a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java index 0231963b9..e4aedd421 100644 --- a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java +++ b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java @@ -16,12 +16,12 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.ImageUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.form.ui.WidgetInfoConfig; import com.fr.general.ComparatorUtils; import com.fr.stable.Constants; -import com.fr.stable.CoreGraphHelper; import com.fr.stable.ListMap; import com.fr.stable.StringUtils; import com.fr.transaction.Configurations; @@ -39,6 +39,9 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; /** * carl:自定义Icon编辑 @@ -452,13 +455,7 @@ public class CustomIconPane extends BasicPane { String path = jf.getSelectedFile().getAbsolutePath(); // 图片存储有最大值48*48限制,没有超过最大值时,按原图大小存储,超过最大值后,压缩至最大值存储 Image image = BaseUtils.readImage(path); - BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(Math.min(image.getWidth(null), IconManager.MAXSTORAGE_ICONWIDTH), - Math.min(image.getHeight(null), IconManager.MAXSTORAGE_ICONHEIGHT), BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = bufferedImage.createGraphics(); - g2d.drawImage(image, 0, 0, Math.min(image.getWidth(null), IconManager.MAXSTORAGE_ICONWIDTH), Math.min(image.getHeight(null), IconManager.MAXSTORAGE_ICONHEIGHT), null); - bufferedImage.flush(); - g2d.dispose(); - iconImage = bufferedImage; + iconImage = ImageUtils.scale((BufferedImage) image, Math.min(image.getWidth(null), IconManager.MAXSTORAGE_ICONWIDTH), Math.min(image.getHeight(null), IconManager.MAXSTORAGE_ICONHEIGHT), true, Image.SCALE_SMOOTH); if (iconImage != null) { showImageLabel.setIcon(new ImageIcon(iconImage)); }