SWT TrayItem.setImage 在 Mac 状态栏中无法正确缩放

发布于 2024-11-16 23:52:38 字数 392 浏览 3 评论 0原文

在我的跨平台 SWT Java 应用程序中,我使用 TrayItem 的 setImages() 函数来设置停靠栏和状态栏图标。该图标是 128x128 透明 PNG。状态和托盘图标在 Windows 和 Linux 发行版上都得到了适当的剪切,但在 Mac 上,我遇到了一些问题,导致状态栏图标两侧出现奇怪的填充,如下所示:

让我感到奇怪的是,这适用于除 Mac 之外的所有其他平台。例如,这里是我的 Linux 机器上没有问题的相同状态栏图标:

有谁知道如何防止Mac 上有这个额外的填充吗?

On my cross-platform SWT Java application, I'm using TrayItem's setImages() function to set the dock and status bar icon. The icon is a 128x128 transparent PNG. The status and tray icons are appropriately clipped on both Windows and Linux distributions, but on the Mac I have problems that make the status bar icon appear with strange padding on both sides like this:

It's strange to me that this is working on all other platforms but the Mac. For instance, here is the same status bar icon without the problem on my Linux box:

Does anyone have any idea how to prevent this extra padding on the Mac?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福不弃 2024-11-23 23:52:38

我在 SWT Cocoa 源中发现了这个问题。

public void setImage (Image image) {
    checkWidget ();
    if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
    super.setImage (image);
    double /*float*/ width = 0;
    if (image == null) {
        view.setImage (null);
    } else {
        /*
         * Feature in Cocoa.  If the NSImage object being set into the view is
         * the same NSImage object that is already there then the new image is
         * not taken.  This results in the view's image not changing even if the
         * NSImage object's content has changed since it was last set into the
         * view.  The workaround is to temporarily set the view's image to null
         * so that the new image will then be taken.
         */
        NSImage current = view.image ();
        if (current != null && current.id == image.handle.id) {
            view.setImage (null);
        }
        view.setImage (image.handle);
        if (visible) {
            width = image.handle.size ().width + BORDER;
        }
    }
    item.setLength (width);
}

问题出在 width = image.handle.size ().width + BORDER; 行上,它仅采用图像的纯大小(在您的情况下为 128 px)。我没有找到任何合适的解决方法(我看到您在 SWT bugzilla 上发布了错误报告)。

因此(目前)避免此错误的唯一方法是缩小托盘图像。

I found the problem in SWT Cocoa sources.

public void setImage (Image image) {
    checkWidget ();
    if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
    super.setImage (image);
    double /*float*/ width = 0;
    if (image == null) {
        view.setImage (null);
    } else {
        /*
         * Feature in Cocoa.  If the NSImage object being set into the view is
         * the same NSImage object that is already there then the new image is
         * not taken.  This results in the view's image not changing even if the
         * NSImage object's content has changed since it was last set into the
         * view.  The workaround is to temporarily set the view's image to null
         * so that the new image will then be taken.
         */
        NSImage current = view.image ();
        if (current != null && current.id == image.handle.id) {
            view.setImage (null);
        }
        view.setImage (image.handle);
        if (visible) {
            width = image.handle.size ().width + BORDER;
        }
    }
    item.setLength (width);
}

The problem is on the line width = image.handle.size ().width + BORDER; which just takes pure size of image (in your case it's 128 px). I didn't found any suitable workaround (I saw you post bug report on SWT bugzilla).

So only way to avoid this bug (for now) is to make your tray image smaller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文