Converting Android Bitmap to LibGdx’s Texture

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(). Runnable() {
        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);
          // now you have the texture to do whatever you want

Leave a Comment