converting drawable resource image into bitmap

前端 未结 6 1839
星月不相逢
星月不相逢 2020-12-02 05:22

I am trying to use the Notification.Builder.setLargeIcon(bitmap) that takes a bitmap image. I have the image I want to use in my drawable folder so how do I con

6条回答
  •  情深已故
    2020-12-02 05:43

    Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
    Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
    

    Since API 22 getResources().getDrawable() is deprecated, so we can use following solution.

    Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo,  getContext().getTheme());
    Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();
    

提交回复
热议问题