title: Can't compress a recycled bitmap
body: <p>I'm trying to save a Layout into an Image in the SDCard but I get this error. I tried several codes I found in this forum but all of them have the same compress call that is giving the error. </p>
  
  <p>This is the code I use for saving the image:</p>
  
  <pre><code>private Bitmap TakeImage(View v) {
          Bitmap screen = null;
          try {
              v.setDrawingCacheEnabled(true);
  
              v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                      MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
              v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
  
              v.buildDrawingCache(true);
              screen = v.getDrawingCache();
              v.setDrawingCacheEnabled(false); // clear drawing cache
          } catch (Exception e) {
              e.printStackTrace();
          }
          return screen;
      }
  </code></pre>
  
  <p>And this is the code for saving it in the SDCard:</p>
  
  <pre><code>private void saveGraph(Bitmap graph, Context context) throws IOException {
          OutputStream fOut = null;
          File file = new File(Environment.getExternalStorageDirectory()
                  + File.separator + "test.jpg");
          fOut = new FileOutputStream(file);
  
          graph.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
          fOut.flush();
          fOut.close();
  
          MediaStore.Images.Media.insertImage(getContentResolver(),
                  file.getAbsolutePath(), file.getName(), file.getName());
  }
  </code></pre>
  
  <p>I'm getting the error:</p>
  
  <blockquote>
    <p>Can't compress a recycled  bitmap in the compress call!</p>
  </blockquote>