4

I'm using cocos2d.

Now I've added some images in the layer, and played around a bit.

I'm trying to save the whole screen as image file.

How can I do this?

Reno
  • 33,594
  • 11
  • 89
  • 102
Noman
  • 4,049
  • 10
  • 38
  • 59

2 Answers2

2

The only way to capture the content of a SurfaceView is if you are rendering into it using OpenGL. You can use glReadPixels() to grab the content of the surface. If you are drawing onto the SurfaceView using a Canvas, you can simply create a Bitmap, create a new Canvas for that Bitmap and execute your drawing code with the new Canvas.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • see this link. I have explained my problem here in more detail. http://stackoverflow.com/questions/8531481/cocos-2d-screen-shot-is-black-in-android – Noman Dec 16 '11 at 13:44
1

It is my understanding that cocos2d-android also has a CCRenderTexture class with the saveBuffer method. In that case have a look at my CCRenderTexture demo program and blog post for cocos2d-iphone which gives you an example for how to create a screenshot using CCRenderTexture and saveBuffer. The same principle should be applicable to cocos2d-android.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217