How to convert to color in bitmap?

I have a color as an integer, and I want this color to be in raster form.
Is there any way to do this?

I tried

Drawable d = new ColorDrawable(Color.parseColor("#ffffff"));
Bitmap b = ((BitmapDrawable)d).getbitmap();

But the above code gives an error Unable to pass ColorDrawable to BitmapDrawable

Is there another way?

Actual code

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);
                    }
                }
            }
    );
+4
source share
1 answer

Yes there is. You just like that:

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 using the methods of the Color class, such as Color.argb () or Color.rgb ()

Thus, you will have a bitmap image with the width, height and filling of the specified color.

: . . , , Canvas, .

+9

All Articles