系统托盘图标看起来扭曲 [英] System Tray icon looks distorted
问题描述
我正在尝试使用Java添加图标并显示到系统托盘中。但是,图标总是太小,或者在区域中被切断。
它是左起第二个,如果你不知道的话。
I'm trying to have an icon be added and displayed to the system tray using Java. However the icon is always either too small, or its cut off in areas. Its the second one from left in case you couldn't tell.
我在这里做错了什么?如何让这个图标完全显示?用于系统托盘的标准图标大小是什么?
What am I doing wrong here? How can I get this icon to be displayed fully? What's the standard icon size to be used for system tray?
编辑:我正在使用AWT SystemTray和TrayIcon
I am using AWT SystemTray and TrayIcon
推荐答案
从磁盘检索实际图像资源后,您可以通过动态创建假并获取其宽度来将其调整为所需大小。
After you've retrieved the actual image resource from disk, you can resize it to the size you need by creating a "fake" one on-the-fly and taking its width.
我发现这比使用 setImageAutoSize(true)
方法,因为该方法不能平滑地缩放图像所有。
I found that this was better than using the setImageAutoSize(true)
method, as that method does not scale the image smoothly at all.
BufferedImage trayIconImage = ImageIO.read(getClass().getResource("/path/to/icon.png"));
int trayIconWidth = new TrayIcon(trayIconImage).getSize().width;
TrayIcon trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
这篇关于系统托盘图标看起来扭曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!