Android Java:从十六进制值创建位图

30

有人能建议一种从十六进制值创建小的纯色位图图像的方法吗?


你目前尝试了什么?或者至少你想要实现什么,一些背景信息会更好。 - Francisco Spaeth
到目前为止还没有尝试过任何东西。我一直在寻找一种方法来做它,但是没有运气。 - Paul
4个回答

83

你也可以使用Bitmap.eraseColor()为位图设置纯色。

示例:

  import android.graphics.Bitmap;
  ...
  Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  image.eraseColor(android.graphics.Color.GREEN);

10

我想我可能有答案。从技术上讲,我认为在Android上比在“pc”上要容易得多。上次我搜索创建位图(.bmp)的方法时,我只找到了一些Android函数和BitmapFactory非安卓版本,但对我来说没有用。

请看这个网站:http://developer.android.com/reference/android/graphics/Bitmap.html
这一点可能适用于您:

static Bitmap createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)

返回一个指定宽度和高度的不可变位图,每个像素值设置为颜色数组中的相应值。


5
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas (image);
int HEX=0xFF888888;
canvas.drawColor (HEX);

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接