Android View.getDrawingCache returns null, only null

后端 未结 10 872
遇见更好的自我
遇见更好的自我 2020-11-22 13:06

Would anyone please try to explain to me why

public void addView(View child) {
  child.setDrawingCacheEnabled(true);
  child.setWillNotCacheDrawing(false);
          


        
10条回答
  •  遇见更好的自我
    2020-11-22 13:28

    if getDrawingCache is always returning null guys: use this:

    public static Bitmap loadBitmapFromView(View v) {
         Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);                
         Canvas c = new Canvas(b);
         v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
         v.draw(c);
         return b;
    }
    

    Reference: https://stackoverflow.com/a/6272951/371749

提交回复
热议问题