From 1081d29cdc06ad1ba2a45facce8aa08bb9696790 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 14 Jun 2017 20:00:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/preview/FilePreviewPane.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/preview/FilePreviewPane.java b/designer/src/com/fr/design/mainframe/alphafine/preview/FilePreviewPane.java index 50938d48a5..15b69aab27 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/preview/FilePreviewPane.java +++ b/designer/src/com/fr/design/mainframe/alphafine/preview/FilePreviewPane.java @@ -1,22 +1,25 @@ package com.fr.design.mainframe.alphafine.preview; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.mainframe.alphafine.AlphaFineConstants; import javax.swing.*; import java.awt.*; +import java.awt.image.BufferedImage; /** * Created by XiaXiang on 2017/5/2. */ public class FilePreviewPane extends JPanel { - public FilePreviewPane(Image image) { + public FilePreviewPane(BufferedImage image) { + setLayout(new BorderLayout()); UILabel label = new UILabel(); - label.setOpaque(true); - label.setBackground(Color.white); - float scale = image.getWidth(null) / 380; - image = image.getScaledInstance(380, (int) (image.getHeight(null) / scale), Image.SCALE_SMOOTH); - label.setIcon(new ImageIcon(image)); + float widthScale = (AlphaFineConstants.RIGHT_WIDTH) / (float) image.getWidth(); + float heightScale = (AlphaFineConstants.CONTENT_HEIGHT) / (float) image.getHeight(); + Image showImage; + showImage = widthScale > heightScale? image.getScaledInstance((int) (image.getWidth() * heightScale), AlphaFineConstants.CONTENT_HEIGHT, Image.SCALE_SMOOTH) : image.getScaledInstance(AlphaFineConstants.RIGHT_WIDTH, (int) (image.getWidth() * widthScale), Image.SCALE_SMOOTH); + label.setIcon(new ImageIcon(showImage)); add(label); } }