title: Convert prepared layout to bitmap and save as image in file
body: <p>I need to save my prepared layout to image file in external memory</p>
  
  <p>For now I've tried to get my layout, enable drawing cache, pass to bitmap and save in file</p>
  
  <pre><code>LayoutInflater inflate = LayoutInflater.from(this);
      View view = inflate.inflate(R.layout.to_send, null);
      view.setDrawingCacheEnabled(true);
      Bitmap returnedBitmap;
      if (view.getMeasuredHeight() &lt;= 0) {
          view.measure(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
          returnedBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
          returnedBitmap.recycle();
          Canvas c = new Canvas(returnedBitmap);
          view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
          view.draw(c);
      }
      else {
          returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
          Canvas canvas = new Canvas(returnedBitmap);
          Drawable bgDrawable = view.getBackground();
          if (bgDrawable != null)
              bgDrawable.draw(canvas);
          else
              canvas.drawColor(Color.WHITE);
          view.draw(canvas);
      }
      //Bitmap bitmap = content.getDrawingCache();
      File fPath = Environment.getExternalStorageDirectory();
      File f = new File(fPath + "Send.png");
      try {
          if (!f.exists()) {
              f.createNewFile();
          }
          FileOutputStream strm = new FileOutputStream(f);
          returnedBitmap.compress(Bitmap.CompressFormat.PNG, 80, strm);
          strm.close();
          //content.invalidate();
      }
      catch (Exception e){
          e.printStackTrace();
      } finally {
          view.setDrawingCacheEnabled(false);}
  </code></pre>