Convert Texture to bufferedImage?

Is there an easy way to convert a Texture to a BufferedImage? Or, I guess the Texture.getImage() part?

yeah, AwtConverter

1 Like

Sweet, thanks!

For anyone that happens to come across this the class I used is called ImageToAwt.



I needed it for resizing Textures as well as just grabbing the BufferedImage. Not sure if there’s a better function or not but this seems to work just fine if anyone wants to try it. Doesn’t support mipping, I only needed it for very basic purposes.



[java]

public static Texture ResizeTexture(Texture tex, int width, int height)

{

BufferedImage texImage = ImageToAwt.convert(tex.getImage(), false, true, 0);

BufferedImage scaledImage = new BufferedImage(width, height, texImage.getType());

Graphics2D graphics2D = scaledImage.createGraphics();

graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

graphics2D.drawImage(texImage, 0, 0, width, height, null);

graphics2D.dispose();

return new Texture2D(new AWTLoader().load(scaledImage, false));

}

[/java]

1 Like