How to make a screen snap

Started by tao, March 17, 2014, 02:02:29 PM

Previous topic - Next topic

tao

Hi,

I'm trying to create a snapshot of current frame. The way I'm thinking is like,

1) Create a FrameBuffer, and setRenderTarget() to a self-created Texture.
2) Call World.renderScene(fb) and World.draw(fb), and the current frame will render to the above Texture.
3) Then I can use the texture and display is as a snapshot or save it.

Is that OK?

Thanks.

Irony

What do you need it for? Just for screenshots? There are easier ways for that :)
Most devices have a certain button combination or a gesture to capture the screen (google it), or if you are using Eclipse, switch to DDMS view, there you have a screen capture button.

EgonOlsen

You can't save the texture, because you can't access the data rendered into it. It's better to use http://www.jpct.net/jpct-ae/doc/com/threed/jpct/FrameBuffer.html#getPixels() instead and convert the int[]-array into an image that can then be saved.

tao

Thanks Irony and Egon, I'm going to use snapshot as some 'cool' effect in game  :), not for saving actually. What I want is like rendering screen content to a texture and displaying it in a photo frame. So am I doing the right way?

EgonOlsen

In that case....Yes. Just make sure that you are using OpenGL ES 2.0 mode for this. With 1.x, rendering into a texture is limited and not very reliable.

tao

Hi Egon,

Here is my snap shot code.

   public void createScreenSnap() {
      final int width = /* Screen Width */
      final int height = /* Screen Height */
      if (texScreenSnap == null) {
         texScreenSnap = new Texture(width, height);
      }
      FrameBuffer fb = new FrameBuffer(width, height); /* Exception Here !!!! */
      fb.setRenderTarget(texScreenSnap);
      fb.clear(RGBColor.BLACK);
      if (world != null){         
         world.renderScene(fb);
         world.draw(fb);
      }
      fb.dispose();
   }

I get follow exception at [new FrameBuffer(width, height)].

03-19 09:07:39.325: E/AndroidRuntime(28372): java.lang.RuntimeException: [ 1395191259321 ] - ERROR: java.lang.RuntimeException: [ 1395191259319 ] - ERROR: java.lang.RuntimeException: [ 1395191259318 ] - ERROR: java.lang.RuntimeException: [ 1395191259316 ] - ERROR: Failed to load and compile vertex shaders!

03-19 09:07:39.325: E/AndroidRuntime(28372):    at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:94)

Am I making something wrong?

Thanks,

EgonOlsen

To use OpenGL ES2.0, you have to setup your gl context accordingly. Have a look at the HelloShader example to see how to do this.

sushobhit

I am also stuck kindof same issue :

I think we both could get on if this is Solved :
Bitmap bitmap;
mGLView.setDrawingCacheEnabled(true);
bitmap = mGLView.getDrawingCache(); // Here you get the screen cap of the View
// then compress it...
bitmap.compress(android.graphics.Compression.PNG,100,outputstream);

sushobhit

?? this is not working just getting a blank output
if this could be somehow rectified I think the issue could be resolved..

EgonOlsen

No, that's different. The OT asks for a way to get the rendered image and reuse it in the app, which is a basic render-to-texture effect. You want to externalize the rendered image. I've already posted an answer to your actual thread about this topic.