如何加载图片?
我想加载一个图像以设置为纹理,但它有错误。 它引发了一个例外。 请帮我。
Exception in thread "main" java.lang.IllegalArgumentException: Texture:illegal image size
at javax.media.j3d.TextureRetained.checkImageSize(TextureRetained.java:419)
at javax.media.j3d.TextureRetained.initImage(TextureRetained.java:364)
at javax.media.j3d.Texture.setImage(Texture.java:959)
at javaapplication1.Draw.Creat(Draw.java:63)
at javaapplication1.Draw.<init>(Draw.java:30)
at javaapplication1.Main.main(Main.java:22)
编辑
我检查图像尺寸是否为 128 * 128。 如果这是真的? 我的图像格式是 *.jpg
这是我的代码。
public class Draw extends Applet{
public Draw() {
BufferedImage image = null;
try {
image = ImageIO.read(new File("1.jpg"));
} catch (Exception e) {
}
TextureLoader loader = new TextureLoader(image, "RGB",
TextureLoader.ALLOW_NON_POWER_OF_TWO);
ImageComponent2D icd = loader.getImage();
Texture2D texture2D = new Texture2D();
texture2D.setImage(0, icd);
}
I want load an image for set to a texture but it has error.
it trowed an exception.
please help me.
Exception in thread "main" java.lang.IllegalArgumentException: Texture:illegal image size
at javax.media.j3d.TextureRetained.checkImageSize(TextureRetained.java:419)
at javax.media.j3d.TextureRetained.initImage(TextureRetained.java:364)
at javax.media.j3d.Texture.setImage(Texture.java:959)
at javaapplication1.Draw.Creat(Draw.java:63)
at javaapplication1.Draw.<init>(Draw.java:30)
at javaapplication1.Main.main(Main.java:22)
edit
I check that my image size was 128 * 128.
if this true?
my image format is *.jpg
this is my code.
public class Draw extends Applet{
public Draw() {
BufferedImage image = null;
try {
image = ImageIO.read(new File("1.jpg"));
} catch (Exception e) {
}
TextureLoader loader = new TextureLoader(image, "RGB",
TextureLoader.ALLOW_NON_POWER_OF_TWO);
ImageComponent2D icd = loader.getImage();
Texture2D texture2D = new Texture2D();
texture2D.setImage(0, icd);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在API 中查找TextureLoader。
Look up TextureLoader in the API.