2

I want to take a system screenshot (not layout's screenshot) of an Android device... I followed this:

Android OpenGL Screenshot

but, where is the gl variable? How to create it?

Community
  • 1
  • 1
user2123185
  • 37
  • 1
  • 4
  • gl comes in as a parameter to the function, it is not locally stored. Guessing they did this because the had a context in a higher level object and just wanted to pass it into a modularized routine to capture screenshots as bitmaps. – trumpetlicks Mar 01 '13 at 13:08
  • "I want to take a system screenshot (not layout's screenshot) of an Android device" -- this is not possible except on rooted devices. If you read the SO question you link to, you will realize that it is for taking screenshots of your *own* OpenGL context, not "a system screenshot". – CommonsWare Mar 01 '13 at 13:40
  • @CommonsWare do you know any answer to this? – Maveňツ Aug 01 '18 at 09:24
  • The media projection APIs introduced in Android 5.0 probably capture OpenGL output, though I have not tried that personally. – CommonsWare Aug 01 '18 at 10:36

1 Answers1

0

In my case, I'm working in NDK thus, C++ call some method in Java then that method some bool var

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

and then take capture glview screen with these method :

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())));
}
Sung
  • 1,036
  • 1
  • 8
  • 22