Browse Source
【问题原因】Windows环境下,jdk11的缩放会造成绘制启动图片模糊 【改动思路】使用2倍图,然后用1倍图的尺寸绘制图片,再经过jdk11的缩放之后显示效果会好一些final/10.0
Yvan
4 years ago
3 changed files with 68 additions and 1 deletions
@ -0,0 +1,58 @@
|
||||
package com.fr.start.common; |
||||
|
||||
import com.bulenkov.iconloader.IconLoader; |
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.locale.impl.SplashMark; |
||||
import com.fr.general.locale.LocaleCenter; |
||||
|
||||
import javax.swing.Icon; |
||||
import java.awt.Dimension; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* @author Yvan |
||||
* @version 10.0 |
||||
* Created by Yvan on 2020/10/27 |
||||
*/ |
||||
public class SplashPane4WinAndJDK11 extends SplashPane{ |
||||
/** |
||||
* 启动画面图片路径 |
||||
*/ |
||||
private String imagePath; |
||||
|
||||
public SplashPane4WinAndJDK11() { |
||||
this.imagePath = getSplashPath4WinAndJdk11(); |
||||
} |
||||
|
||||
private String getSplashPath4WinAndJdk11() { |
||||
String path = "/com/fr/design/images/splash_10@2x.png"; |
||||
String filePath = this.getClass().getResource("/").getPath(); |
||||
// 某些定制jar里面没有两倍图,判断一下,如果文件不存在,就返回一倍图的path
|
||||
if (new File(filePath + path).exists()) { |
||||
return path; |
||||
} |
||||
return (String) LocaleCenter.getMark(SplashMark.class).getValue(); |
||||
} |
||||
|
||||
@Override |
||||
protected void paintComponent(Graphics g) { |
||||
super.paintJComponent(g); |
||||
BufferedImage image = BaseUtils.readImage(imagePath); |
||||
Graphics2D newG = (Graphics2D)g.create(0, 0, image.getWidth(), image.getHeight()); |
||||
newG.scale(0.5D, 0.5D); |
||||
newG.drawImage(image, 0, 0, null); |
||||
newG.scale(1.0D, 1.0D); |
||||
newG.dispose(); |
||||
paintShowText((Graphics2D) g); |
||||
g.dispose(); |
||||
} |
||||
|
||||
@Override |
||||
Dimension getSplashDimension() { |
||||
Icon icon = IconLoader.getIcon(imagePath); |
||||
return new Dimension(icon.getIconWidth() / 2, icon.getIconHeight() / 2); |
||||
} |
||||
} |
Loading…
Reference in new issue