Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I use this code to save any graphic drawed using canvas, like fingerpaint or similar, I hope can be useful for your case</p> <p>Set the instance as global</p> <pre><code>MyDraw d; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); d = new MyDraw (this); setContentView (d); } </code></pre> <p>And put this in the case of your onOptionsItemSelected();</p> <pre><code>case 4: try { Bitmap bitmap = Bitmap.createBitmap(d.getWidth(),d.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); d.draw(canvas); File folder = new File(Environment.getExternalStorageDirectory()+ "/DCIM/Camera/"); if (!folder.exists()) folder.mkdirs(); String fileName = Environment.getExternalStorageDirectory()+ "/DCIM/Camera/img.jpg""; if (new File(fileName).exists()) new File(fileName).delete(); OutputStream stream = new FileOutputStream(fileName); /* * Write bitmap to file using JPEG or PNG and 100% quality hint * for JPEG. */ bitmap.compress(CompressFormat.JPEG, 100, stream); stream.close(); } catch (Exception e) { // TODO Auto-generated catch block Toast.makeText(this, "Error: " + e.getMessage(),Toast.LENGTH_LONG).show(); } break; </code></pre> <p>UPDATE: Check that your emulated device has SD Card <img src="https://i.stack.imgur.com/KvO3d.png" alt="enter image description here"></p> <p>Remind that you have to add the permissions to manifest</p> <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload