How to Save the drawing canvas in android?

try this code

View content = your_view;
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = content.getDrawingCache();
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
File file = new File(path+"/image.png");
FileOutputStream ostream;
try {
    file.createNewFile();
    ostream = new FileOutputStream(file);
    bitmap.compress(CompressFormat.PNG, 100, ostream);
    ostream.flush();
    ostream.close();
    Toast.makeText(getApplicationContext(), "image saved", 5000).show();
} catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(getApplicationContext(), "error", 5000).show();
}