gpt4 book ai didi

java - LWJGL 图标只显示在任务栏

转载 作者:行者123 更新时间:2023-11-30 11:15:59 24 4
gpt4 key购买 nike

我已经设置了一个将图像加载到 ByteBuffer 并调用 Display.setIcon() 的方法,这部分有效。这将设置任务栏的图标,但将窗口的图标保留为默认的 LWJGL 图标。我需要调用另一个 Display 方法吗?或者这与 Windows 有关。

如果需要,这里是加载图标的方法:

public static final ByteBuffer[] getIcon()
{
Image image = Toolkit.getDefaultToolkit().getImage("rw_icon.PNG");
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);

try
{
tracker.waitForAll();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
tracker.removeImage(image);

BufferedImage bufImage = new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics = bufImage.createGraphics();
graphics.drawImage(image, 0, 0, null);
graphics.dispose();
image.flush();

ByteBuffer buffer = ByteBuffer.allocateDirect(32*32*4);
buffer.clear();
byte[] bufferData = (byte[])bufImage.getRaster().getDataElements(0, 0, 32, 32, null);
buffer.put(bufferData);
buffer.rewind();

return (new ByteBuffer[] {buffer});
}

最佳答案

没有。

您只需将两个版本的图标 (16x16, 32x32) 的数组传递给 setIcon(..) 方法。

您似乎误解了 ByteBuffer[]。您应该传递一组不同 ByteBuffer。不仅仅是一个只有一个元素的 ByteBuffer 数组。因此,最好创建一个新方法,它基本上只执行您的 getIcon() 方法所做的事情,但需要一个 String 作为文件路径。这样您就可以轻松地创建图标字节缓冲区的真实数组。

public static int setIcon(java.nio.ByteBuffer[] icons)

Sets one or more icons for the Display. On Windows you should supply at least one16x16 icon and one 32x32. Linux (and similar platforms) expect one32x32 icon. Mac OS X should be supplied one 128x128 icon Theimplementation will use the supplied ByteBuffers with image data inRGBA (size must be a power of two) and perform any conversionsnescesarry for the specific platform.NOTE: The display will make adeep copy of the supplied byte buffer array, for the purpose ofrecreating the icons when you go back and forth fullscreen mode. Youtherefore only need to set the icon once per instance.

http://lwjgl.org/javadoc/org/lwjgl/opengl/Display.html#setIcon(java.nio.ByteBuffer[])

关于java - LWJGL 图标只显示在任务栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25101704/

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