Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX creating texture from base64 PNG ByteArrayInputStream

I just decided to make the change from Slick2D to LibGDX. However, for me to be able to port my game over to LibGDX I need help understanding how to create textures in LibGDX from my game data files.

My game data files are encrypted and the images are encoded in base64 so I can keep them all in one txt file. How do I create a LibGDX texture from a ByteArrayInputStream.

In Slick2D I converted the base64 string into a bufferedimage. But I don't want to do that for LibGDX since I may want to get it on android soon.

EDIT: I just figured it out, kind of. I did it like so:

   Texture bucket;
    String base64 = "base64 string too long to paste"
    byte[] decodedBytes = Base64Coder.decode(base64);
    bucket = new Texture(new Pixmap(decodedBytes, 0, decodedBytes.length));

However, now the image is flipped vertically... Am I missing something?

like image 818
Ike Yousuf Avatar asked Jun 03 '13 17:06

Ike Yousuf


1 Answers

Texture bucket;
String base64 = "base64 string too long to paste"
byte[] decodedBytes = Base64Coder.decode(base64);
bucket = new Texture(new Pixmap(decodedBytes, 0, decodedBytes.length));

That worked for me.

It was flipped because I changed the OrthgraphicsCamera to have 0,0 at the upper left.

like image 128
Ike Yousuf Avatar answered Oct 23 '22 23:10

Ike Yousuf