[SOLVED] Exporting texture from assets

Hi guys,


I’m working on a small tool app to help me design dynamic skies. Basically, rather than creating a sky with code in the game project, I want to generate one with this app at runtime, then export the whole sky with all textures in a folder containing an xml config. The idea is to drop this folder in another project’s asset folder and recreate this sky with a simple


CustomSky mySky = new CustomSky();



Almost all of this works fine but:


To create the final sky folder, I want to export the texture images that exist in my asset folder into the destination sky folder. Here is the code I use to do that:



ByteBuffer buf = assetManager.loadTexture(orgTexturePath).getImage().getData().get(0);


byte[] bytes = new byte[buf.capacity()];

buf.get(bytes, 0, bytes.length);

in = new ByteArrayInputStream(bytes);

File dstFile = new File(FileHelper.pathCombine(destFilePath, srcFile.getName()));

OutputStream out = new FileOutputStream(dstFile);

FileHelper.copy(in, out);


public static void copy(InputStream in, OutputStream out) throws IOException {

// Transfer bytes from in to out

byte[] buf = new byte[1024];

int len;

while ((len = in.read(buf)) > 0) {

out.write(buf, 0, len);






This code raises no exception and I get the expected destination file. But the resulting texture file is not the image, the file is way too large and will not open with an image editor. The original texture image in the asset pack is around 150k and the resulting image is about 3.5 megs! So I suppose the getData() method doesn’t really give me the original image file data. Was is converted and I must convert it back? Am I simply not selecting the right data with the getData method? Or is it a non-JME related problem in the way I use Java to accomplish this? (Still JME and Java newbie, sorry.)

Thanks a lot!

Its raw image data, theres an ImageToAwt helper class that allows you to convert the image to an awt BufferedImage that you can save using ImageIO.

1 Like

Oh great! I don’t think I would have figured that out any time soon. :slight_smile: Thanks normen!