问题
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?
回答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.
回答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.
来源:https://stackoverflow.com/questions/8470485/surface-view-as-a-bitmap-in-android