Android的OpenGL的屏幕截图 [英] Android OpenGL Screenshot

查看:853
本文介绍了Android的OpenGL的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多关于采取在Android上我的OpenGL对象的屏幕截图,并拿出<一个href="http://stackoverflow.com/questions/3310990/taking-screenshot-of-android-opengl/4666820#4666820">this解。它的工作很好,但在我的情况下,我对相机视图的顶级相机视图和OpenGL预览(透明背景)。因此,我想要做的就是让OpenGL的截图与透明的背景,而不是黑色。 正如我说我已经尝试过上面的链接,它的工作,但我只能和黑色的背景。这是有点复杂,要弄清楚如何让在这种特殊情况下摆脱了黑色背景的。 希望有人能帮助我,尽快如果可能的话(也是我认为解决方案是容易的,我只是简单的东西)。 谢谢你。

I've searched a lot about taking screenshot of my OpenGL object on Android and come up with this solution. It worked great but in my case I have camera view and opengl view(with transparent background) on top of camera view. So what I want to do is to get opengl screenshot with transparent background instead of black. As I said I have tried link above and it worked but I'm stuck with black background. It's little bit complicated to figure out how to get rid of the black background in this particular case. Hope somebody could help me and asap if it's possible(also I think the solution is easy, I'm just missing something simple). Thank you.

推荐答案

我用下面的方法和工作就像一个冠军。

I used following method and worked like a champ.

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;
}

您只需要调用

YourClass.SavePixels(0,0,width,height,gl);

我希望这会为你工作?

I hope this will work for you...

谢谢, Midhun

Thanks, Midhun

这篇关于Android的OpenGL的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆