Android Java 从十六进制值创建位图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11453705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Java create bitmap from hex value
提问by Paul
Can anyone suggest a way to create a small solid colored bitmap image from a hex value?
任何人都可以建议一种从十六进制值创建小的纯色位图图像的方法吗?
采纳答案by AxP
I think I may have the answer. Technically I believe it is much easier on Android than on a "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.
我想我可能有答案。从技术上讲,我认为在 Android 上比在“PC”上容易得多。上次我搜索创建位图(.bmp)时,我只找到了一些Android功能和BitmapFactory
非android的,这对我不起作用。
Please look at this site: http://developer.android.com/reference/android/graphics/Bitmap.html
This point could fit for you:
请看这个网站: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)
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.
static Bitmap createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
返回具有指定宽度和高度的不可变位图,每个像素值设置为颜色数组中的相应值。
回答by theartofrain
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);
回答by LiNKeR
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas (image);
int HEX=0xFF888888;
canvas.drawColor (HEX);
回答by BlackHatSamurai
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