2011-05-15 43 views

回答

4

出於明顯的安全原因,您無法訪問幀緩衝區。

+0

根本不可能訪問主要的gl上下文來繪製覆蓋圖? – Emanuele 2011-05-16 19:18:58

3

你可能想要做的是研究glReadPixels()函數。我運行了一個測試,我用glsurfaceview和image view分割了屏幕,並想看看我是否可以從glview中獲取像素並創建一個Bitmap,然後將其應用於ImageView。經過一番研究,我發現使用glReadPixels()的作品,但你必須在使用它們作爲android位圖之前變換像素。這是我最終使用的方法。我相信我在另一個論壇上發現了這種方式。

public Bitmap SaveGLPixels(int x, int y, int w, int h, GL10 gl) 

    { 

     int b[]=new int[w*h]; 

     int bt[]=new int[w*h]; 

     IntBuffer ib=IntBuffer.wrap(b); 

     ib.position(0); 

     gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib); 

     for(int i=0; i<h; i++) 

     {//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-i-1)*w+j]=pix1; 

       } 

     }     
     Bitmap.Config bconfig = Bitmap.Config.RGB_565; 
     Bitmap sb=Bitmap.createBitmap(bt, w, h, bconfig); 

     return sb; 

    }