Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SWT TrayItem.setImage在Mac状态栏中无法正确缩放_Java_Macos_Swt_Statusbar - Fatal编程技术网

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

Java SWT TrayItem.setImage在Mac状态栏中无法正确缩放,java,macos,swt,statusbar,Java,Macos,Swt,Statusbar,在我的跨平台SWT Java应用程序中,我使用TrayItem的setImages()函数设置停靠和状态栏图标。图标为128x128透明PNG。在Windows和Linux发行版上,状态和托盘图标都被适当地剪裁,但在Mac上,我遇到了一些问题,使状态栏图标两侧都出现了奇怪的填充,如下所示: 对我来说很奇怪,除了Mac之外,其他平台上都可以使用。例如,这里是相同的状态栏图标,在我的Linux设备上没有问题: 有人知道如何防止Mac上的这种额外填充吗?我在SWT Cocoa源中发现了这个问题 p

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

对我来说很奇怪,除了Mac之外,其他平台上都可以使用。例如,这里是相同的状态栏图标,在我的Linux设备上没有问题:


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

我在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上发布错误报告)


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

如果没有任何代码,这将很难调试。通过一些谷歌搜索,看起来你应该能够做到这一点而没有任何问题。你试过在eclipse.platform.swt上提问并搜索可能的错误吗?swt Snippet 143是如何找到你的?你试过其他图像格式(jpeg,gif)吗?我可能对透明度有问题。我的代码与代码片段#143中发布的代码非常相似。我将尝试使用不同的格式,但似乎这可能是SWT中的某种错误。你是对的。几天前,我向SWT团队提交了一份bug报告,但忘了更新这篇反映这一点的帖子。不幸的是,这个问题的存在是因为它需要大量重写代码。查看我的错误报告只是一个跟进-如果你有同样的问题,他们已经在上提交了一个补丁。