I have done a sample painting app using APIDemo’s FingerPaint app. Instead of the “usual” pattern of setContentView(R.layout.main) it uses a class MyView that extends View and sets content as setContentView(new MyView(this)); now whatever I draw I want to save it in the SDCard. For this I require to know the rootview using getRootView. This is got by the object of layout(for ex: LinearLayout L1 = new…) L1.getRootView. Because I am using this MyView, I am not able to get the rootview nor able to save the bitmap.
myview.setDrawingCacheEnabled(true);
myview.requestFocus();
myview.getRootView();
System.out.println("MYVIEW = "+myview);
myview.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
myview.layout(0, 0, myview.getMeasuredWidth(), myview.getMeasuredHeight());
myview.buildDrawingCache(true);
mBitmap = myview.getDrawingCache();
//System.out.println("myview.getDrawingCache() = "+newview.getDrawingCache());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
myview.setDrawingCacheEnabled(false); // clear drawing cache
System.out.println("BITMAP = "+mBitmap);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (Exception e)
{
e.printStackTrace();
}
I want to know how do I save my drawing using a menu button click?
Thank you
After a lot of effort into research I bumped into this http://blahti.wordpress.com/2010/11/18/how-to-save-jpeg-files-in-the-android-emulator/ This solved my issue of saving the drawing.