Convert Buffered Image to Texture?

I have generated an Alpha Texture for My terrain, but it is currenlty a Buffered Image, however my terrain requires it to be of the type: Texture, how can i convert a BufferedImage to a Texture?

Thank you

You can instantiate an AWTLoader and use it to convert:
http://hub.jmonkeyengine.org/javadoc/com/jme3/texture/plugins/AWTLoader.html#load(java.awt.image.BufferedImage,%20boolean)

…but I wonder if it wouldn’t be better to just draw directly to a JME image. See: ImageRaster and/or the ImagePainter plugin.

I have an image, but i want to convert it into a texture.

Image alpha = alphaGen.renderAlphaMap();

    BufferedImage alphaBImg = ImageToAwt.convert(alpha, false, true, 0);
    Texture alpha = //What to put here?
    
    mat_terrain.setTexture("Alpha", alpha);

http://hub.jmonkeyengine.org/javadoc/com/jme3/texture/plugins/AWTLoader.html#load(java.awt.image.BufferedImage,%20boolean)

1 Like
@TastyLemons said: I have an image, but i want to convert it into a texture.

Image alpha = alphaGen.renderAlphaMap();

    BufferedImage alphaBImg = ImageToAwt.convert(alpha, false, true, 0);
    Texture alpha = //What to put here?
    
    mat_terrain.setTexture("Alpha", alpha);</blockquote>

Wait… if you already have an image then why convert it to a BufferedImage?

Maybe your confusion is not knowing how to tunnel through the javadoc?

If you see Texture has something like:

Then you can click on various real implementations to see what they do. In your case, you want a 2D texture so Texture2D is probably what you want to look at.

1 Like