What is best way to get ImageBuffer from a Jmonkey Texture?

I am making a 2D imgage to 3D spatial converter.

The use case is the diamond pickaxe from minecraft from a 16x16.png file to a 3D Spatial.
I have the conversion working but want to know a better way / jmonkey way of loading the image file

Currently I am using this with a hard coded URL
[java]
String IMAGE_NAME = “diamond_pickaxe.png”;
URL url = ImageProcessTestMain.class.getResource(IMAGE_NAME);
BufferedImage bufferedImage = ImageIO.read(url);


int width = bufferedImage .getWidth();
int height = bufferedImage .getHeight();
int[][] result = new int[height][width];

    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            result[row][col] = bufferedImage .getRGB(col, row);
            System.out.print(" " + result[row][col]);
        }
        System.out.println(" ");
    }

[/java]

I would like to use something inside of JMonkey that would give me the same data using the assetManager

[java]

Texture texture = assetManager.loadTexture(“Textures/diamond_pickaxe.png”);

texture.getData()???
[/java]

Thanks for any help

You use the ImageRaster function. Also check out the ImagePainer plugin, with this library you can perform draw functions similar to the swing/g3d stuff.

1 Like

That did it thank you!

[java]
private Sprite convertTo2DUsingGetRGBJMEWay(Texture texture) {
ImageRaster imageRaster = ImageRaster.create(texture.getImage());
int width = imageRaster.getWidth();
int height = imageRaster.getHeight();
int[][] result = new int[height][width];

    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            ColorRGBA color = imageRaster.getPixel(col, row);
            result[row][col] = color.asIntRGBA();
           // System.out.print(" " + result[row][col]);
        }
      //  System.out.println(" ");
    }

   ...
}

[/java]