converting drawable resource image into bitmap
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 convert that to bitmap?
You probably mean Notification.Builder.setLargeIcon(Bitmap)
, right? :)
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);
This is a great method of converting resource images into Android Bitmap
s.
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
。
上一篇: Android地图v2缩放以显示所有标记
下一篇: 将可绘制的资源图像转换为位图