Convert GradientDrawable to Bitmap

前端 未结 3 1109
误落风尘
误落风尘 2021-01-20 03:26

I have the following gradient (generated dynamically):

    GradientDrawable dynamicDrawable = new GradientDrawable();
    dynamicDrawable.setGradientType(Gra         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 04:29

    You can use below code mention in: Android: Convert Drawable to Bitmap

    public Bitmap convertToBitmap(Drawable drawable, int widthPixels, int heightPixels) {
        Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(mutableBitmap);
        drawable.setBounds(0, 0, widthPixels, heightPixels);
        drawable.draw(canvas);
    
        return mutableBitmap;
    }
    

提交回复
热议问题