title: How to take screenshot of GLSurfaceView programmatically in android
body: <p>I want to take the screenshot of GlSurfaceView programmatically in android. I am using the below code to achieve this functionality but I could not achieve this functionality. Please help me to take screenshot of GLSurfaceVIew programmatically.</p>
  
  <p>Caling method.</p>
  
  <pre><code>createBitmapFromGLSurface((int)customglSurfaceView.getX(), (int)customglSurfaceView.getY(), 
  </code></pre>
  
  <p>Method Body</p>
  
  <pre><code>public static Bitmap createBitmapFromGLSurface(int x, int y, int w, int h) throws OutOfMemoryError {
      int bitmapBuffer[] = new int[w * h];
      int bitmapSource[] = new int[w * h];
      IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
      intBuffer.position(0);
  
      try {
          glObject.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer);
          int offset1, offset2;
          for (int i = 0; i &lt; h; i++) {
              offset1 = i * w;
              offset2 = (h - i - 1) * w;
              for (int j = 0; j &lt; w; j++) {
                  int texturePixel = bitmapBuffer[offset1 + j];
                  int blue = (texturePixel &gt;&gt; 16) &amp; 0xff;
                  int red = (texturePixel &lt;&lt; 16) &amp; 0x00ff0000;
                  int pixel = (texturePixel &amp; 0xff00ff00) | red | blue;
                  bitmapSource[offset2 + j] = pixel;
              }
          }
      } catch (GLException e) {
          return null;
      }
      return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
  }
  </code></pre>
  
  <p>Thanks</p>