gpt4 book ai didi

java - SWT GC : Color not correctly drawn on Windows

转载 作者:可可西里 更新时间:2023-11-01 14:51:56 28 4
gpt4 key购买 nike

仍在寻找解决方案

我有以下问题:我使用 SWT GC 将 GraphNodes 中包含的图形绘制到 Zest Graph。就 Linux 和 MacOS 而言,一切正常。但是当我在 Windows 上运行我的 jar 时,节点看起来很奇怪。颜色未正确绘制且没有透明度(通过 GCsetAlpha() 实现)。

这里有两个截图来说明我的问题:

Linux:

enter image description here

Windows :

enter image description here

编辑:

我刚刚创建了这个有效的“迷你”示例来进行测试。如果有人知道为什么矩形在 Windows 上是黑色的,我将不胜感激。这是 back.png 图片:This is the <code>back.png</code>

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.IContainer;

public class MiniExample
{
public static void main(String[] args)
{
Display display = Display.getDefault();
Shell shell = new Shell(display);

Graph graph = new Graph(shell, SWT.NONE);
graph.setSize(100, 100);

CustomFigure fig = new CustomFigure(new Label());
fig.setSize(-1, -1);
CustomNode node = new CustomNode(graph, SWT.NONE, fig);
node.setLocation(5, 5);

shell.pack();
shell.open();

while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
}

/* Minimal helper class for the figure */
static class CustomFigure extends Figure
{
private Image background = new Image(Display.getDefault(), "back.png");
private GC gcBack = new GC(background);
private Label all = new Label(background);
private Color blau = new Color(Display.getDefault(), 19, 59, 94);

public CustomFigure(Label label)
{
ToolbarLayout layout = new ToolbarLayout();
setLayoutManager(layout);
setMiddle(3);
add(all);
}

/* The problem has to occur somewhere here... */
public void setMiddle(int value)
{
gcBack.setBackground(blau);
gcBack.setForeground(blau);
gcBack.setAlpha(255);

/* color background blue and draw the nr of connections */
gcBack.drawRoundRectangle(6, 6, 15, 15, 3, 3);
gcBack.fillRoundRectangle(6, 6, 15, 15, 3, 3);
gcBack.setForeground(ColorConstants.white);
gcBack.drawText(value+"", 9, 6, true);

gcBack.setAlpha(255);

all.repaint();
}
}

/* Minimal helper class for the node */
static class CustomNode extends GraphNode
{
public CustomNode(IContainer graphModel, int style, CustomFigure figure)
{
super(graphModel, style, figure);
}
@Override
protected IFigure createFigureForModel()
{
return (IFigure) this.getData();
}
}
}

最佳答案

您的程序中使用的灰色图像与 Tobias Willig 发布的白色图像明显不同:

灰色:

Image Width: 28 Image Length: 28
Bitdepth (Bits/Sample): 1
Channels (Samples/Pixel): 1
Pixel depth (Pixel Depth): 1
Colour Type (Photometric Interpretation): PALETTED COLOUR (1 colours, 0 transparent)
Image filter: Single row per byte filter
Interlacing: No interlacing
Compression Scheme: Deflate method 8, 32k window
Resolution: 2835, 2835 (pixels per meter)
FillOrder: msb-to-lsb
Byte Order: Network (Big Endian)
Number of text strings: 0 of 0

白色:

Image Width: 28 Image Length: 28
Bitdepth (Bits/Sample): 8
Channels (Samples/Pixel): 3
Pixel depth (Pixel Depth): 24
Colour Type (Photometric Interpretation): RGB
Image filter: Single row per byte filter
Interlacing: No interlacing
Compression Scheme: Deflate method 8, 32k window
Resolution: 2835, 2835 (pixels per meter)
FillOrder: msb-to-lsb
Byte Order: Network (Big Endian)
Number of text strings: 0 of 0

如您所见,灰色图像的颜色类型仅包含一种颜色,而白色图像的一种颜色是 RGB。

所以肯定是图像导致了您的问题。

关于java - SWT GC : Color not correctly drawn on Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10982544/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com