【问题标题】:How to use OpenGl to take a screenshot on android如何使用OpenGL在android上截屏
【发布时间】:2013-03-01 11:25:50
【问题描述】:

我想截取 Android 设备的系统截图(不是布局的截图)...我跟着这个:

Android OpenGL Screenshot

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

【问题讨论】:

  • gl 作为函数的参数传入,它不是本地存储的。猜测他们这样做是因为在更高级别的对象中有一个上下文,并且只是想将其传递给模块化例程以将屏幕截图捕获为位图。
  • “我想截取 Android 设备的系统屏幕截图(不是布局的屏幕截图)”——除了 root 设备,这是不可能的。如果您阅读链接到的 SO 问题,您会意识到它是用于截取 自己的 OpenGL 上下文的屏幕截图,而不是“系统屏幕截图”。
  • @CommonsWare 你知道这个问题的答案吗?
  • Android 5.0 中引入的媒体投影 API 可能会捕获 OpenGL 输出,虽然我没有亲自尝试过。

标签: android opengl-es screenshot pixels


【解决方案1】:

就我而言,我在 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())));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多