I have a color in form of integer, and i want that color to be in a Bitmap form.
Is there any way to do so?
I tried
Drawable d = new ColorDrawable(Color.parseColor("#ffffff"));
Bitmap b = ((BitmapDrawable)d).getbitmap();
But the above code give error Cannot cast ColorDrawable to BitmapDrawable
Is there any other way?
Actual code is
Palette.generateAsync(BitmapFactory.decodeFile(songArt),
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(final Palette palette) {
if (Build.VERSION.SDK_INT >= 16) {
Drawable colorDrawable = new ColorDrawable(palette.getDarkVibrantColor(
getResources().getColor(R.color.noti_background)));
notificationCompat.bigContentView.setImageViewResource(R.id.noti_color_bg,
((BitmapDrawable) colorDrawable).getBitmap());
notificationManager.notify(NOTIFICATION_ID, notificationCompat);
}
}
}
);
Yes there is. You can just do it like this:
Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.drawColor(colorInt)
Inside drawColor()
you can also set the color by using the methods of the Color
class like Color.argb(...)
or Color.rgb(...)
That way you will have a bitmap with dimensions width
/height
and filled with the specified color.
Further explanation: You create a Bitmap
object with your specified dimensions. Then you create a Canvas
object and attach the Bitmap
object to it. This way everything that is drawn using the Canvas
object methods gets drawn on the Bitmap
object.
In the end you have a Bitmap
object with your drawings in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With