Browse Source

MOBILE-21196 【性能】移动端》报表》打开少数单元格插入图片的模板,出现加载缓慢,时间在5s以上不等 设计器部分

bugfix/10.0
zack 6 years ago
parent
commit
f9fb1389e6
  1. 4
      designer-base/src/main/java/com/fr/design/gui/frpane/ImgChooseWrapper.java
  2. 2
      designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ImageBackgroundQuickPane.java
  3. 2
      designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ImagePreviewPane.java
  4. 2
      designer-base/src/main/java/com/fr/design/style/background/image/ImagePreviewPane.java
  5. 19
      designer-base/src/main/java/com/fr/design/utils/ImageUtils.java
  6. 4
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java
  7. 22
      designer-realize/src/main/java/com/fr/design/report/SelectImagePane.java

4
designer-base/src/main/java/com/fr/design/gui/frpane/ImgChooseWrapper.java

@ -7,7 +7,6 @@ import com.fr.design.style.background.image.ImageFileChooser;
import com.fr.design.style.background.image.ImagePreviewer; import com.fr.design.style.background.image.ImagePreviewer;
import com.fr.design.utils.ImageUtils; import com.fr.design.utils.ImageUtils;
import com.fr.general.ImageWithSuffix; import com.fr.general.ImageWithSuffix;
import com.fr.stable.CoreGraphHelper; import com.fr.stable.CoreGraphHelper;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -16,6 +15,7 @@ import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.Image; import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
/** /**
@ -103,7 +103,7 @@ public class ImgChooseWrapper {
if (imageFileChooser.isCheckSelected()) { if (imageFileChooser.isCheckSelected()) {
imageWithSuffix = ImageUtils.defaultImageCompWithSuff(selectedFile); imageWithSuffix = ImageUtils.defaultImageCompWithSuff(selectedFile);
} else { } else {
Image image = BaseUtils.readImage(selectedFile.getPath()); BufferedImage image = BaseUtils.readImage(selectedFile.getPath());
String type = ImageUtils.getImageType(selectedFile); String type = ImageUtils.getImageType(selectedFile);
imageWithSuffix = new ImageWithSuffix(image, type); imageWithSuffix = new ImageWithSuffix(image, type);
} }

2
designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ImageBackgroundQuickPane.java

@ -114,7 +114,7 @@ public class ImageBackgroundQuickPane extends BackgroundQuickPane {
@Override @Override
public Background updateBean() { public Background updateBean() {
ImageFileBackground imageBackground = new ImageFileBackground(previewPane.getImage(), suffix); ImageFileBackground imageBackground = new ImageFileBackground(previewPane.getImageWithSuffix());
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem());
imageBackground.setLayout(imageStyle.getImageLayout()); imageBackground.setLayout(imageStyle.getImageLayout());
return imageBackground; return imageBackground;

2
designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ImagePreviewPane.java

@ -304,7 +304,7 @@ public class ImagePreviewPane extends JComponent implements Scrollable, ImagePre
@Override @Override
public void setImage(Image image) { public void setImage(Image image) {
setImageWithSuffix(image == null ? null : new ImageWithSuffix(image)); setImageWithSuffix(ImageWithSuffix.build(image));
} }

2
designer-base/src/main/java/com/fr/design/style/background/image/ImagePreviewPane.java

@ -63,7 +63,7 @@ public class ImagePreviewPane extends JComponent implements Scrollable, ImagePre
@Override @Override
public void setImage(Image image) { public void setImage(Image image) {
setImageWithSuffix(image == null ? null : new ImageWithSuffix(image)); setImageWithSuffix(ImageWithSuffix.build(image));
} }

19
designer-base/src/main/java/com/fr/design/utils/ImageUtils.java

@ -1,6 +1,7 @@
package com.fr.design.utils; package com.fr.design.utils;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.frpx.util.ImageIOHelper;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.ImageWithSuffix; import com.fr.general.ImageWithSuffix;
@ -70,7 +71,7 @@ public class ImageUtils {
return null; return null;
} }
BufferedImage srcImg = BaseUtils.readImage(imageFile.getPath()); BufferedImage srcImg = BaseUtils.readImage(imageFile.getPath());
Image desImg = srcImg; BufferedImage desImg = srcImg;
try { try {
if (canbeCompressedToJPEG(imageFile)) { if (canbeCompressedToJPEG(imageFile)) {
@ -186,11 +187,23 @@ public class ImageUtils {
/** /**
* 获取图片类型 * 获取图片类型
* 先根据ImageReader获取ImageReader获取不到就拿后缀
* *
* @param imageFile 图片文件 * @param imageFile 图片文件
* @return 图片类型(JPEG, PNG, GIF) * @return 图片类型(JPEG, PNG, GIF)
*/ */
public static String getImageType(File imageFile) { public static String getImageType(File imageFile) {
String imageType = getImageTypeByImageReader(imageFile);
return StringUtils.EMPTY.equals(imageType) ? ImageIOHelper.getSuffix(imageFile) : imageType;
}
/**
* 根据ImageReader获取图片类型
*
* @param imageFile 图片文件
* @return 图片类型(JPEG, PNG, GIF)
*/
public static String getImageTypeByImageReader(File imageFile) {
try { try {
ImageInputStream iis = ImageIO.createImageInputStream(imageFile); ImageInputStream iis = ImageIO.createImageInputStream(imageFile);
Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
@ -226,7 +239,7 @@ public class ImageUtils {
* @param scale 缩放比例比例大于1时为放大小于1大于0为缩小 * @param scale 缩放比例比例大于1时为放大小于1大于0为缩小
* @param opacityCompatible 是否处理背景透明 * @param opacityCompatible 是否处理背景透明
*/ */
public static Image scale(BufferedImage srcImg, float scale, boolean opacityCompatible) { public static BufferedImage scale(BufferedImage srcImg, float scale, boolean opacityCompatible) {
if (scale < 0) { if (scale < 0) {
// 自动修正负数 // 自动修正负数
scale = -scale; scale = -scale;
@ -234,7 +247,7 @@ public class ImageUtils {
int width = mul(Integer.toString(srcImg.getWidth(null)), Float.toString(scale)).intValue(); // 得到源图宽 int width = mul(Integer.toString(srcImg.getWidth(null)), Float.toString(scale)).intValue(); // 得到源图宽
int height = mul(Integer.toString(srcImg.getHeight(null)), Float.toString(scale)).intValue(); // 得到源图长 int height = mul(Integer.toString(srcImg.getHeight(null)), Float.toString(scale)).intValue(); // 得到源图长
return scale(srcImg, width, height, opacityCompatible); return CoreGraphHelper.toBufferedImage(scale(srcImg, width, height, opacityCompatible));
} }
private static BigDecimal mul(String v1, String v2) { private static BigDecimal mul(String v1, String v2) {

4
designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

@ -68,6 +68,7 @@ import com.fr.file.FILE;
import com.fr.file.FileNodeFILE; import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.ImageWithSuffix;
import com.fr.general.ModuleContext; import com.fr.general.ModuleContext;
import com.fr.grid.Grid; import com.fr.grid.Grid;
import com.fr.grid.GridUtils; import com.fr.grid.GridUtils;
@ -89,6 +90,7 @@ import com.fr.report.elementcase.TemplateElementCase;
import com.fr.report.poly.PolyWorkSheet; import com.fr.report.poly.PolyWorkSheet;
import com.fr.report.worksheet.WorkSheet; import com.fr.report.worksheet.WorkSheet;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.module.Module; import com.fr.stable.module.Module;
@ -621,7 +623,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
if (workBook instanceof WorkBookAdapter) { if (workBook instanceof WorkBookAdapter) {
elem.setValue(new CellImagePainter(cellImage)); elem.setValue(new CellImagePainter(cellImage));
} else { } else {
elem.setValue(cellImage.getImage()); elem.setValue(ImageWithSuffix.build(cellImage.getImage(),cellImage.getSuffix()));
} }
} }

22
designer-realize/src/main/java/com/fr/design/report/SelectImagePane.java

@ -2,16 +2,15 @@ package com.fr.design.report;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.Style; import com.fr.base.Style;
import com.fr.base.frpx.pack.PictureCollection;
import com.fr.base.frpx.util.ImageIOHelper;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.style.background.image.ImageFileChooser; import com.fr.design.style.background.image.ImageFileChooser;
import com.fr.design.style.background.image.ImagePreviewPane; import com.fr.design.style.background.image.ImagePreviewPane;
import com.fr.design.utils.ImageUtils;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ImageWithSuffix;
import com.fr.report.cell.Elem; import com.fr.report.cell.Elem;
import com.fr.report.cell.cellattr.CellImage; import com.fr.report.cell.cellattr.CellImage;
import com.fr.report.cell.painter.CellImagePainter; import com.fr.report.cell.painter.CellImagePainter;
@ -28,6 +27,7 @@ import java.awt.GridLayout;
import java.awt.Image; import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
/** /**
@ -46,11 +46,6 @@ public class SelectImagePane extends BasicPane {
private Image previewImage = null; private Image previewImage = null;
/**
* 默认格式
*/
private String suffix = PictureCollection.DEFAULT_SUFFIX;
private File imageFile; private File imageFile;
public SelectImagePane() { public SelectImagePane() {
@ -127,13 +122,12 @@ public class SelectImagePane extends BasicPane {
if (selectedFile != null && selectedFile.isFile()) { if (selectedFile != null && selectedFile.isFile()) {
String filePath = selectedFile.getPath(); String filePath = selectedFile.getPath();
suffix = ImageIOHelper.getSuffix(filePath); BufferedImage image = BaseUtils.readImage(filePath);
Image image = BaseUtils.readImage(filePath);
CoreGraphHelper.waitForImage(image); CoreGraphHelper.waitForImage(image);
imageFile = selectedFile; imageFile = selectedFile;
setImageStyle(); setImageStyle();
previewPane.setImage(image); previewPane.setImageWithSuffix(ImageWithSuffix.build(image, ImageUtils.getImageType(selectedFile)));
previewPane.setImageStyle(imageStyle); previewPane.setImageStyle(imageStyle);
previewImage = image; previewImage = image;
} else { } else {
@ -184,7 +178,6 @@ public class SelectImagePane extends BasicPane {
setImage((Image) value); setImage((Image) value);
} else if (value instanceof CellImagePainter) { } else if (value instanceof CellImagePainter) {
setImage(((CellImagePainter) value).getImage()); setImage(((CellImagePainter) value).getImage());
suffix = ((CellImagePainter) value).getSuffix();
} }
style = cell.getStyle(); style = cell.getStyle();
@ -214,11 +207,8 @@ public class SelectImagePane extends BasicPane {
public CellImage update() { public CellImage update() {
CellImage cellImage = new CellImage(); CellImage cellImage = new CellImage();
cellImage.setImage(previewPane.getImage()); cellImage.setImage(previewPane.getImageWithSuffix());
cellImage.setStyle(this.imageStyle); cellImage.setStyle(this.imageStyle);
if (suffix != null) {
cellImage.setSuffix(suffix);
}
return cellImage; return cellImage;
} }

Loading…
Cancel
Save