Browse Source

Merge pull request #1173 in DESIGN/design from ~BRUCE.DENG/design:feature/10.0 to feature/10.0

* commit 'e3a10b6e4e322b6a3af5a65bc93bc8b6661d609f':
  MOBILE-23325 【单选按钮样式】图文按钮:上传图片后,移动端图片显示很模糊
research/11.0
Bruce.Deng 5 years ago
parent
commit
b003130b0e
  1. 19
      designer-base/src/main/java/com/fr/design/utils/ImageUtils.java
  2. 13
      designer-base/src/main/java/com/fr/design/web/CustomIconPane.java

19
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());

13
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));
}

Loading…
Cancel
Save