【问题标题】:SWT TrayItem.setImage does not scale properly in Mac status barSWT TrayItem.setImage 在 Mac 状态栏中无法正确缩放
【发布时间】:2011-09-22 09:18:54
【问题描述】:

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

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

有人知道如何在 Mac 上防止这种额外的填充吗?

【问题讨论】:

  • 如果没有任何代码,这将很难调试。根据一些谷歌搜索,看起来你应该能够毫无问题地做到这一点。
  • 您是否尝试过在 eclipse.platform.swt 上提出问题并在 bugs.eclipse.org/bugs 上搜索可能存在的错误?
  • 您是否尝试过其他图像格式(jpeg、gif)?我可能对透明度有问题..
  • 我的代码与 Snippet #143 中发布的代码非常相似。我将尝试使用不同的格式,但这似乎是 SWT 中的某种错误。

标签: java macos swt statusbar


【解决方案1】:

我在 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 像素)。我没有找到任何合适的解决方法(我看到你在 SWT bugzilla 上发布了错误报告)。

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

【讨论】:

  • 你是对的。几天前,我向 SWT 团队提交了一份错误报告,但忘记更新这篇反映这一点的帖子。不幸的是,这个问题的存在是因为它需要对大部分代码进行强烈的重写。请参阅我的错误报告here
  • 只是后续行动 - 如果您遇到同样的问题,他们已经在 bug report 上提交了补丁。
猜你喜欢
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 2018-06-22
  • 2019-05-18
  • 2013-09-24
  • 2011-05-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多