2

我想拍摄 Android 设备的系统屏幕截图(不是布局的屏幕截图)......我遵循了这个:

Android OpenGL 截图

但是, gl 变量在哪里?如何创建它?

4

1 回答 1

0

就我而言,我在 NDK 中工作,因此 C++ 在 Java 中调用了一些方法,然后该方法调用了一些 bool var

if(capture)
{saveAlbum(gl);
capture=false; 
}

然后使用以下方法捕获 glview 屏幕:

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)&0xffff0000;
                       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;
        }  

void saveAlbum(GL10 gl)
        {   
               Bitmap bmp = SavePixels(0, 0, windowWIDTH, windowHEIGHT, gl);  // display wid,height must be
            bmp = rotate(bmp,DefinallyROTATION);
           path =MediaStore.Images.Media.insertImage(m_Context.getContentResolver(), bmp, "hi", null);
             IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED); 
             intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); 
             intentFilter.addDataScheme("file"); 
             m_Context.registerReceiver(mReceiver, intentFilter);
             m_Context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
                        + Environment.getExternalStorageDirectory())));
}
于 2013-03-02T00:44:07.297 回答