gpt4 book ai didi

JavaGDK+ : Pixbuf image not found

转载 作者:行者123 更新时间:2023-12-02 10:19:28 27 4
gpt4 key购买 nike

org.gnome.gdk.Pixbuf 构造函数的文件路径参数相对于哪个目录?我应该将文件放在哪里?

Main.java

public class Main
{
public static void main( String... args )
{
Gtk.init( args );
new Example();
Gtk.main();
}
}

示例.java

public class Example
{
private Pixbuf icon;

public Example()
{
try {
icon = new Pixbuf( "images/bolt.png" );
} catch ( FileNotFoundException e ) {
e.printStackTrace();
}
}
}

它抛出以下异常:

java.io.FileNotFoundException: images/web.png not found

我的目录结构是:

enter image description here

最佳答案

使用 this.getClass().getResourceAsStream(/images/bolt.png) 获取 InputStream 并使用此 answer将其转换为 byte[],您可以将其传递给 Pixbuf 构造函数。

如果您使用的是 Java 9,您还可以在 InputStream 上调用 readAllBytes()

关于JavaGDK+ : Pixbuf image not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54448095/

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