我有一个以整数形式表示的颜色,我想将其转换成位图形式。
有没有什么方法可以这样做?
我尝试过
Drawable d = new ColorDrawable(Color.parseColor("#ffffff"));
Bitmap b = ((BitmapDrawable)d).getbitmap();
但是上述代码会出现错误:“无法将ColorDrawable转换为BitmapDrawable”
是否有其他方法?
实际代码如下:
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);
}
}
}
);
draw(color)
命令中设置一种颜色... 你回答得非常误导人。 - IAmGroot