I am trying to implement a simple Facebook profile image request function in a game that is being developed with the Libgdx engine. I would like to receive the requested image and ultimately display it on the screen. It is advisable that this work both on my desktop and on Android.
The problem occurs when I try to create a Pixmap object using a profile image, since the profile image is a progressive jpeg that libgdx cannot load. Code example:
inStream = new URL(url).openStream(); byte[] buffer = new byte[1024 * 200]; int readBytes = 0; while (true) { int length = inStream.read(buffer, readBytes, buffer.length - readBytes); if (length == -1) break; readBytes += length; } Pixmap pixmap = new Pixmap(buffer, 0, readBytes);
Since the image is uploaded, I have no way to convert the image to the usual jpeg or png format using software. I tried to use the ImageIO package (among some others) to decode the image, but it is also not capable of handling progressive jpeg. I could not find a solution that would work on both platforms.
Any suggestions to overcome this problem? At least if I could handle this for Android, maybe I could come up with something else to implement on the desktop.
source share