Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Save the drawing canvas in android?

I am using this API demo of the Developer site, THIS DEMO.

But i am wonder that how to save that image in to My Andrtoid Device. Is please anyone give the Code to save that drawn image to the Android Device.

Thanks.

like image 354
Shreyash Mahajan Avatar asked Nov 18 '11 07:11

Shreyash Mahajan


2 Answers

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();
}
like image 196
Pratik Avatar answered Sep 23 '22 12:09

Pratik


drawView.setDrawingCacheEnabled(true);
Bitmap bm = null;
drawView.destroyDrawingCache();
bm=drawView.getDrawingCache();

Then write the bitmap to file using bitmap factory.

like image 35
Jana Avatar answered Sep 21 '22 12:09

Jana