Can't compress a recycled bitmap

后端 未结 3 2271
迷失自我
迷失自我 2021-02-19 22:20

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 gi

相关标签:
3条回答
  • 2021-02-19 22:36

    The solution is: you only need to copy the bitmap.

    imageneViewer.setImageBitmap(lienzo.getDrawingCache().copy(Bitmap.Config.RGB_565, false));
    
    0 讨论(0)
  • 2021-02-19 22:38

    This is probably causing the bitmap to be recycled:

    v.setDrawingCacheEnabled(false); // clear drawing cache
    

    If you want the bitmap to hang around longer, then you should copy it.

    0 讨论(0)
  • 2021-02-19 22:52

    This resolved my issues.

    View drawingView = get_your_view_for_render;
    drawingView.buildDrawingCache(true);
    Bitmap bitmap = drawingView.getDrawingCache(true).copy(Config.RGB_565, false);
    drawingView.destroyDrawingCache();
    // bitmap is now OK for you to use without recycling errors.
    
    0 讨论(0)
提交回复
热议问题