简体   繁体   English

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

[英]Android Java create bitmap from hex value

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

Alternatively, you can use Bitmap.eraseColor() to set a solid color for your bitmap. 或者,您可以使用Bitmap.eraseColor()为您的位图设置纯色。

Example: 例:

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

I think I may have the answer. 我想我可能有答案。 Technically I believe it is much easier on Android than on a "pc". 从技术上讲,我相信它在Android上比在“PC”上容易得多。 The last time I searched to create a bitmap (.bmp), I only found some Android functions and the BitmapFactory for non-android, which didn't work for me. 我最后一次搜索创建位图(.bmp)时,我只找到了一些Android函数和非android的BitmapFactory ,这对我来说不起作用。

Please look at this site: http://developer.android.com/reference/android/graphics/Bitmap.html 请查看此站点: http//developer.android.com/reference/android/graphics/Bitmap.html
This point could fit for you: 这一点可能适合你:

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

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array. 返回具有指定宽度和高度的不可变位图,每个像素值设置为colors数组中的对应值。

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

Use the createBitmap() . 使用createBitmap()

Here is a link that will show you how: http://developer.android.com/reference/android/graphics/Bitmap.html 这是一个链接,将向您展示如何: http//developer.android.com/reference/android/graphics/Bitmap.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM