user3293494
user3293494

Reputation: 609

How to cache surfaceview in a bitmap?

In my android app there are two SurfaceViews. One SurfaceView is drawn upon when user touches it. I want to copy and replicate the content of this SurfaceView on the other SurfaceView. Probably this can be done by caching the content of the first SurfaceView in a bitmap and then drawing the bitmap on the second SurfaceView. But how to cache the first SurfaceView ?

There are a few similar questions on this forum but they really do not work out for me.

Upvotes: 2

Views: 2844

Answers (1)

Vilda
Vilda

Reputation: 1793

This: surfaceview.getDrawingCache(); will return the bitmap out of the SurfaceView and then you can draw it to the second SurfaceView: canvas.drawBitmap(bitmap, 0, 0, null);.

Another way is to copy the canvas, not the surface view, like this:

Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

This means, that if you'll draw something on the canvas, it will be actually drawn on the bitmap.

Upvotes: 3

Related Questions