Android opengles2屏幕截图

Android opengles2屏幕截图,android,opengl-es-2.0,Android,Opengl Es 2.0,我试图捕捉屏幕上呈现的内容的截图。我尝试过使用glreadpixels,但结果都是零。我很高兴知道是否还有其他方法可以捕获GLSURFACHEVIEW。非常感谢 以下是我从另一个线程获得的代码片段: public Bitmap savePixels(int x, int y, int w, int h){ int b[]=new int[w*(y+h)]; int bt[]=new int[w*h]; IntBuffer ib=IntBuffer.

我试图捕捉屏幕上呈现的内容的截图。我尝试过使用glreadpixels,但结果都是零。我很高兴知道是否还有其他方法可以捕获GLSURFACHEVIEW。非常感谢

以下是我从另一个线程获得的代码片段:

public Bitmap savePixels(int x, int y, int w, int h){
        int b[]=new int[w*(y+h)];
        int bt[]=new int[w*h];
        IntBuffer ib=IntBuffer.wrap(b);
        ib.position(0);

        GLES20.glReadPixels(x, 0, w, y+h, GLES20.GL_RGBA, GLES20.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;

                    int test = pix;
                    if (pix > 0)    
                        System.out.println(test%256 + " " + (test/256)%256 + " " + (test/256/256)%256 + " " + test/256/256/256);
                }
        }
        return Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
}
公共位图保存像素(整数x、整数y、整数w、整数h){
int b[]=新int[w*(y+h)];
int bt[]=新的int[w*h];
IntBuffer ib=IntBuffer.wrap(b);
ib.位置(0);
GLES20.glReadPixels(x,0,w,y+h,GLES20.GL_RGBA,GLES20.GL_无符号字节,ib);
对于(inti=0,k=0;i16)&0xff;

int pr=(pixWhat版本的Android?在ICS之前,需要root,ICS Up具有内置的Power+Vol Up…如果渲染到自己的帧缓冲区,您应该能够将帧缓冲区转换为可以保存的图像(通过从颜色缓冲区获取像素)您的意思是渲染到纹理吗?读取缓冲区设置是否正确?请参阅glReadBuffer()