Create or convert BufferedImage to com.jme3.texture.Image

Is there a way to create a com.jme3.texture.Image in code and draw to it ?
The constructor wants a format, dimensions and the data as a bytebuffer, but thats what i want to create by painting on the image after i created it.
With normal BufferedImage i would do something like this:
[java]
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage image = null;
image = gc.createCompatibleImage(
512, 512,
Transparency.TRANSLUCENT);
Graphics g = image.getGraphics();
// draw something on the grafics
g.dispose();
[/java]
Is there something like this for the jme Images too i am overlooking ?
Or can i create a BufferedImage and then convert it to a jme Image somehow ?
Either way would work for me but i guess creating a jme Image right away would be more perfomant.

There is ImageRaster built into core, but it sounds like you want ImagePainter. It’s available as a plugin from the update center inside the SDK.

1 Like

Thanks, ImagePainter was exactly what i was looking for.

Be aware that ImagePainter works entirely in the CPU so is not the fastest. For pre or occasional rendering it works fine, I wouldn’t recommend trying to do anything complex every frame though!

You can also draw on the bufferedImage the way you are used to, and convert it to JME image using the stock class AWTLoader.
You can then update it using ImagePainter or directly rasters if you need only set pixels.

1 Like