if (YayoGameMidlet.shotScreen) {
// GL to Android Bitmap Color Modifier values.
final float[] cmVals = {
0, 0, 1, 0, 0,
0, 1, 0, 0, 0,
1, 0, 0, 0, 0,
0, 0, 0, 1, 0,
};
// Collect the pixels from the GLSurfaceView.
int x = 0;
int y = 0;
int w = YayoGameMidlet.screenWidth;
int h = YayoGameMidlet.screenHeight;
int[] pix = new int[w * h];
IntBuffer PixelBuffer = IntBuffer.wrap(pix);
PixelBuffer.position(0);
gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer);
Bitmap glBitmap = Bitmap.createBitmap(pix, w, h, Bitmap.Config.ARGB_8888);
PixelBuffer = null;
pix = null;
// Translate pixel colors to make them android compatible.
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(cmVals)));
Bitmap newImage = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newImage);
canvas.drawBitmap(glBitmap, 0, 0, paint);
glBitmap.recycle();
glBitmap = null;
// Generate the overlay from the modified pixels with the help of a matrix.
Matrix matrix = new Matrix();
matrix.preScale(1.0f, -1.0f); // Vertical flip.
YayoGameMidlet.screenBmp = Bitmap.createBitmap(newImage, 0, 0, newImage.getWidth(), newImage.getHeight(), matrix, true);
newImage.recycle();
newImage = null;
// Done capturing overlay.
YayoGameMidlet.shotScreen = false;
}