P Srinivas Goud
P Srinivas Goud

Reputation: 896

How to save canvas drawing using SurfaceView as image?

How to save canvas drawing using SurfaceView as image not the view.

Upvotes: 1

Views: 2882

Answers (1)

ingsaurabh
ingsaurabh

Reputation: 15269

Try below code might help

    Bitmap bitmap = Bitmap.createBitmap(mSurfaceView.getWidth(), mSurfaceView.getHeight(), Bitmap.Config.ARGB_8888);
mSurfaceView.draw(new Canvas(bitmap));
try {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(saved.png));
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (IOException e) {
    Log.w(TAG, e);
}

Upvotes: 2

Related Questions