如何从RGB颜色创建位图

Kin*_*pia 3 java rgb android colors bitmap

我正在制作一个使用3个SeekBars的应用程序,以允许用户创建RGB颜色。然后,我想使用WallpaperManager将这种颜色设置为用户的背景。

如果我有3个值,一个为红色,一个为绿色,一个为蓝色,是否有办法创建仅用一种颜色填充的正方形位图?

Gau*_*ier 6

您可以执行此操作以创建具有选定颜色的平方位图。

// Here you create the bound of your shape
Rect rect = new Rect(0, 0, 1, 1);

// You then create a Bitmap and get a canvas to draw into it
Bitmap image = Bitmap.createBitmap(rect.width(), rect.height(), Config.ARGB_8888);
Canvas canvas = new Canvas(image);

//You can get an int value representing an argb color by doing so. Put 1 as alpha by default
int color = Color.argb(alpha, red, green, blue);

//Paint holds information about how to draw shapes
Paint paint = new Paint();
paint.setColor(color);

// Then draw your shape
canvas.drawRect(rect, paint);
Run Code Online (Sandbox Code Playgroud)