Get bitmap from layout

前端 未结 3 1399
青春惊慌失措
青春惊慌失措 2020-12-05 11:57

I\'m trying to inflate a layout and use that to set a bitmap on an image view. Then, I\'m adding that imageview to a linear layout and displaying the linear layout. Here\'s

相关标签:
3条回答
  • 2020-12-05 12:35

    You cant get bitmap on the views or layout is not being inflated.

    Layout will only getting inflated after OnCreate()

    .

    1.Get bitmap on Button_Clicked(View view){}

    2.Or using a Handle()to post delaying your get bitmap

    3.Make sure drawing cache is created using view.buildDrawingCache();

    0 讨论(0)
  • 2020-12-05 12:41
        /***
     * 
     * @param flameLayout/linearLayout...
     * @param width
     * @param height
     * @return
     */
    public static Bitmap viewToBitmap(View view, int width, int height) {
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        view.draw(canvas);
        return bitmap;
    }
    
    0 讨论(0)
  • 2020-12-05 12:56

    Convert a layout to Bitmap.

    FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bm = view.getDrawingCache();
    
    0 讨论(0)
提交回复
热议问题