Windows 8扭曲了我的TrayIcon [英] Windows 8 Distorts my TrayIcon

查看:168
本文介绍了Windows 8扭曲了我的TrayIcon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 8似乎使托盘图标为20 x 20像素。似乎Java仍然认为它们应该是16 x 16像素。这会导致一些糟糕的失真,因为Java会缩小范围,然后Windows会重新调整内容。以下示例使用这三个图像创建三个托盘图标,如下所示(注意扭曲):

Windows 8 appears to make tray icons be 20 x 20 pixels. It seems as though Java still thinks they should be 16 x 16 pixels. This is causing some bad distortion as Java scales things down, and then Windows scales things back up. The following example uses these three images to create three tray icons that look like this (note the distortion):



import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;

public class TrayTest
{
    public static void main(String[] args) throws Exception
    {
        final SystemTray tray = SystemTray.getSystemTray();

        TrayIcon trayIcon16 = new TrayIcon(getImage("16pxBlue.png"));
        tray.add(trayIcon16);

        TrayIcon trayIcon20 = new TrayIcon(getImage("20pxRed.png"));
        tray.add(trayIcon20);

        TrayIcon trayIcon20autoSize = new TrayIcon(getImage("20pxGreen.png"));
        trayIcon20autoSize.setImageAutoSize(true);
        tray.add(trayIcon20autoSize);
    }

    public static Image getImage(String resource)
    {
        return Toolkit.getDefaultToolkit().createImage(TrayTest.class.getResource(resource));
    }
}

这就是用像素放大的全部内容添加的行(在新标签中打开图像会给你更清晰的视图):

This is what the whole thing looks like magnified with pixel lines added (opening image in a new tab will give you a clearer view):

我的问题:
如何防止Java / Windows 8发生歪曲我的偶像?

My question: How can I prevent Java / Windows 8 from distorting my icons?

推荐答案

16×16大小显然硬编码到Java TrayIcon实现中。我没有看到在运行时更改它的方法。来自 WTrayIconPeer.java

The 16×16 size is apparently hardcoded into the Java TrayIcon implementation. I don't see a way to change it at runtime. From WTrayIconPeer.java:

final static int TRAY_ICON_WIDTH = 16;
final static int TRAY_ICON_HEIGHT = 16;

这需要报告为错误

作为一种解决方法,使用平滑的消除锯齿图标会使失真变得不那么明显。

As a workaround, using smooth, anti-aliased icons will make the distortion less noticeable.

如果你很绝望,你可以使用JNA或JNI编写(或找到?)托盘图标的替代实现。 WTrayIconPeer.java 中的代码和
awt_TrayIcon.cpp 可以作为指南。虽然看起来很多工作。

If you're desperate, you could write (or find?) an alternative implementation of tray icons using JNA or JNI. The code in WTrayIconPeer.java and the corresponding native code in awt_TrayIcon.cpp could serve as a guide. It looks like a lot of work though.

这篇关于Windows 8扭曲了我的TrayIcon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆