Android OpenGL截图

Ale*_*ush 7 android screenshot opengl-es pixels

我已经搜索了很多关于在Android上截取我的OpenGL对象的截图并提出这个解决方案.它工作得很好,但在我的情况下,我在摄像机视图顶部有摄像机视图和opengl视图(透明背景).所以我想做的是获得透明背景而不是黑色的opengl截图.正如我所说,我已经尝试过上面的链接并且它有效但我仍然坚持黑色背景.在这种特殊情况下弄清楚如何摆脱黑色背景有点复杂.希望有人可以帮助我,如果可能的话尽快帮助我(我认为解决方案很简单,我只是简单地遗漏了一些东西).谢谢.

Mid*_*ere 15

我使用了以下方法并且像冠军一样工作.

public static Bitmap SavePixels(int x, int y, int w, int h, GL10 gl)
{  
     int b[]=new int[w*(y+h)];
     int bt[]=new int[w*h];
     IntBuffer ib=IntBuffer.wrap(b);
     ib.position(0);
     gl.glReadPixels(x, 0, w, y+h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);

     for(int i=0, k=0; i<h; i++, k++)
     {//remember, that OpenGL bitmap is incompatible with Android bitmap
      //and so, some correction need.        
          for(int j=0; j<w; j++)
          {
               int pix=b[i*w+j];
               int pb=(pix>>16)&0xff;
               int pr=(pix<<16)&0x00ff0000;
               int pix1=(pix&0xff00ff00) | pr | pb;
               bt[(h-k-1)*w+j]=pix1;
          }
     }


     Bitmap sb=Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
     return sb;
}
Run Code Online (Sandbox Code Playgroud)

你只需要打电话

YourClass.SavePixels(0,0,width,height,gl);
Run Code Online (Sandbox Code Playgroud)

我希望这对你有用......

谢谢,Midhun

  • 如何搞定这个? (6认同)
  • @Midhere ...黑屏拍摄. (4认同)

Wil*_*Kru 5

您提到的解决方案是使用Bitmap.Config.RGB_565不支持Alpha通道的解决方案.

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Run Code Online (Sandbox Code Playgroud)

相反,你应该使用Bitmap.Config.ARGB_8888Bitmap.Config.ARGB_4444.

  • 即使使用Bitmap.Config.ARGB_8888,也会给出黑色背景. (3认同)