将可绘制的资源图像转换为位图
  我正在尝试使用带位图图像的Notification.Builder.setLargeIcon(bitmap) 。  我有我想要在我的可绘制文件夹中使用的图像,所以如何将其转换为位图? 
  你可能是指Notification.Builder.setLargeIcon(Bitmap) ,对吧?  :) 
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);
  这是将资源图像转换为Android Bitmap的一个好方法。 
Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
由于API 22 getResources().getDrawable()已弃用,因此我们可以使用以下解决方案。 
Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), R.drawable.logo, null);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);
 Context可以是您当前的Activity 。 
上一篇: converting drawable resource image into bitmap
下一篇: Drawing a bitmap in a canvas after calling setBitmap doesn't work
