i am trying to convert bitmap into a libGDX Texture by converting:
Bitmap
to byte[]
byte[]
to libGDX Pi
Are you committed to that operational pipeline? Here's an alternate way to do the conversion you asked for:
(arr[i] << 8) | (arr[i]>>24)
Your pipeline above includes several copies and recompressions of pixel data; this pipeline allows you to feed your Bitmap data straight into the texture with only one copy (necessary for the byte format conversion anyway). Would that work for you?
you have to code on a new thread because pixmap class takes time for byte conversion and sometimes returns a temporary pixmap in case the process hasnt finished so its better to run on a seperate thread and your problem will be solved.
hmm another possibility is that you've got a threading issue. I've noticed this kind of problem when loading my own unmanaged textures on the UI thread while libgdx is doing its thing loading textures concurrently on the render thread. If this is the problem the simple solution is to synchronize the creation of the texture with the render thread using Gdx.app.postRunnable. i.e.:
public void onByteArrayOfCroppedImageReciever(byte[] bytes) {
try {
pmap=new Pixmap(bytes, 0, bytes.length);
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
tex=new Texture(pmap);
face=new Sprite(tex);
}
});
} catch(Exception e) {
Gdx.app.log("KS", e.toString());
e.printStackTrace();
}
}
If the goal is to convert an Android Bitmap to a libgdx Texture, you don't need to use Pixmap at all. You can do it directly with the help of simple OpenGL and Android GLUtils. Try the followings; it is 100x faster than your solution. I assume that you are not in the rendering thread (you should not most likely). If you are, you don't need to call postRunnable().
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
Texture tex = new Texture(bitmap.getWidth(), bitmap.getHeight(), Format.RGBA8888);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.getTextureObjectHandle());
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
bitmap.recycle();
// now you have the texture to do whatever you want
}
});