Skip to main content

texture.setImage with illegal image size

3 replies [Last post]
Joined: 2009-10-16

I am new to textures and I'm trying to learn to use them.

I understand that images have to be square, and have a dimension of a power of 2 (1, 2, 4, 8, etc.).

I'm using an image with dimensions 64x64.
However, when I do my setimage(), I get an illegal image size exception. I have verified that the dimensions of my ImageComponent2D are 64x64.

Here is my code:

java.awt.image.BufferedImage image = null;

try {
image ="texture.jpg"));
} catch (Exception e) {
System.out.println("" + e);

if (image != null) {
Texture2D texture = new Texture2D();
ImageComponent2D imageComp = new ImageComponent2D (ImageComponent.FORMAT_RGB, image);
System.out.println("imageComp size: " + imageComp.getWidth() + "x" + imageComp.getHeight());
texture.setImage(0, imageComp);

Does anyone know what might be wrong?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-06-07


please check out Texture2D javadoc: [i]"Note that the default constructor (new Texture2D()) creates a texture object with a width and height of 0 and is, therefore, not useful."[/i]

Give this a try:

Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, image.getWidth, image.getHeight);


Joined: 2009-10-16

Yep, that did the trick. Thanks!!

Joined: 2009-10-16

It's funny, but when I use the utility TextureLoader, I can load my image into the texture object just fine. However, I would still like to learn to load texture images without the crutch of TextureLoader. Can anyone see why the above code would not work?