From b24f4e92623a526f2862f26f532326a8705fcf0d Mon Sep 17 00:00:00 2001 From: Starryi Date: Sat, 24 Jul 2021 12:29:16 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55743=20=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8-=E5=9C=A8=E6=96=B0jar=E4=B8=8B=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=E6=8A=A5=E8=A1=A8=E5=9D=97=EF=BC=8C=E6=94=BE?= =?UTF-8?q?=E5=88=B0=E6=97=A7=E7=89=88=E6=9C=ACjar=E4=B8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=99=A8=E6=98=BE=E7=A4=BA=E9=BB=91=E8=89=B2=E7=BC=A9?= =?UTF-8?q?=E7=95=A5=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 新设计器要能在布局画布上预览背景图,所以报表块的缩略图要变成支持透明的, 但是创建的缩略图BufferImage的透明背景时(0, 0, 0, 0) 2. 旧设计器在从XML中读取缩略图时,只读取RGB数据,也就是只读取了(0, 0, 0), 所以显示了黑色 【改动思路】 新设计器创建的缩略图透明背景为(255, 255, 255, 1) --- .../mainframe/form/FormElementCaseDesigner.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java index b2892e722..567345ff2 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java @@ -39,14 +39,17 @@ import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.worksheet.FormElementCase; import com.fr.report.worksheet.WorkSheet; +import javax.imageio.ImageIO; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JScrollBar; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Transparency; import java.awt.image.BufferedImage; +import java.io.File; /** * 表单中的ElementCase编辑面板 @@ -132,13 +135,22 @@ public class FormElementCaseDesigner int width = size.width; int height = size.height; - image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + // 使用TYPE_INT_RGB和new Color(255, 255, 255, 1)设置有透明背景buffer image, + // 使得创建出来的透明像素是(255, 255, 255, 1),而不是(0, 0, 0, 0) + // 这样不支持透明通道缩略图的旧设计器打开新设计器创建的模版时,就不会创建出拥有黑色背景的缩略图 + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = image.createGraphics(); // 创建一个支持透明背景的buffer image image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); g2d.dispose(); g2d = image.createGraphics(); + // 使用TYPE_INT_RGB和new Color(255, 255, 255, 1)设置有透明背景buffer image, + // 使得创建出来的透明像素是(255, 255, 255, 1),而不是(0, 0, 0, 0) + // 这样不支持透明通道缩略图的旧设计器打开新设计器创建的模版时,就不会创建出拥有黑色背景的缩略图 + g2d.setColor(new Color(255, 255, 255, 1)); + g2d.fillRect(0, 0, (int) size.getWidth(), (int) size.getHeight()); + Grid grid = this.elementCasePane != null ? this.elementCasePane.getGrid() : null; if (grid != null) { boolean oldTranslucent = grid.isTranslucent(); @@ -148,6 +160,8 @@ public class FormElementCaseDesigner grid.setTranslucent(oldTranslucent); } + ImageIO.write(image, "png", new File("/Users/Starryi/test.png")); + } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); }