How can I convert a View to a Drawable?

前端 未结 2 1601
别跟我提以往
别跟我提以往 2020-12-31 14:33

I have a View and I want to convert it into an image in order to store it somewhere. But how can I convert this View to an image?

2条回答
  •  误落风尘
    2020-12-31 15:08

    1. Enable drawing cache on the view:

      view.setDrawingCacheEnabled(true);
      
    2. Create a bitmap from the cache:

      bitmap = Bitmap.createBitmap(view.getDrawingCache());
      
    3. Save the bitmap wherever...

    4. Disable drawing cache:

      view.setDrawingCacheEnabled(false);
      

提交回复
热议问题