0

I'm trying to render a GLSurfaceView to a JPEG using the following code:

FileOutputStream image = FileIO.getInstance().writeFile("racesow/test" + this.frameNum +" .jpg"); // creates an ouputstream in external storage directory
Bitmap bitmap = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(bitmap);
this.game.glView.draw(canvas); // glView is the GLSurfaceView
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, image);
image.flush();
image.close();

I'm executing this code after the complete scene has been rendered to the surfaceview. The images are being created but they're all black. Any ideas?

Andreas Linden
  • 12,489
  • 7
  • 51
  • 67

1 Answers1

1

This is just not implemented (SurfaceView.draw'1, GLSurfaceView). Taking screenshots whilst using OpenGL requires special handling, yet the draw method is not overridden in GLSurfaceView.

However, since it's an open class, you can derive from it and add your own implementation of draw with custom code to take screenshots; or whatever suits you best.

Community
  • 1
  • 1
Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34