我需要在我的 Java 小程序中使用 JPEG 图像。在我的小程序类中,我定义了图像名称并为 ImageBuffer 类创建了一个对象。
String iname= "image1.jpg";
b = new ImageBuffer(iname,this);
在 ImageBuffer 类中,我调用
Image image = null;
image = Toolkit.getDefaultToolkit().getImage(new URL(applet.getCodeBase(),fileName));
虽然这不会标记错误并且图像不再为空,但它没有image
正确初始化。和是height
-1 width
。然而,路径的 url 似乎是正确的: /C:/Users/..../image1.jpg
如何正确加载图像?它目前在我的 Eclipse 项目的 bin 文件中。