gpt4 book ai didi

java - 获取图像的路径并使用 BufferedImage 加载它

转载 作者:行者123 更新时间:2023-12-01 12:33:01 24 4
gpt4 key购买 nike

我不知道为什么在 Java 中它会如此复杂,但我已经在这上面花了好几个小时了。我在\src\resources\resize-cursor.png

中有一个 png 图像

现在,我想将此图像与 BufferedImage 类一起使用

BufferedImage myPicture = null;

try {
// this is just one of the examples I tried... I've already tried like 10 ways to achieve this but I am always getting NullReferenceException
myPicture = ImageIO.read(getClass().getResourceAsStream("\\resources\\resize-cursor.png")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

是否有一种工作方法可以在我的应用程序中链接 png 资源?

最佳答案

您尝试过getClass().getResourceAsStream("/resources/resize-cursor.png")吗?

关于java - 获取图像的路径并使用 BufferedImage 加载它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25792166/

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