Reputation: 1734
Can anyone suggest a way to create a small solid colored bitmap image from a hex value?
Upvotes: 31
Views: 18628
Reputation: 891
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas (image);
int HEX=0xFF888888;
canvas.drawColor (HEX);
Upvotes: 5
Reputation: 153
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.
Please look at this site: 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.
Upvotes: 10
Reputation: 1837
Alternatively, you can use Bitmap.eraseColor() to set a solid color for your bitmap.
Example:
import android.graphics.Bitmap;
...
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
image.eraseColor(android.graphics.Color.GREEN);
Upvotes: 84
Reputation: 23493
Use the createBitmap()
.
Here is a link that will show you how: http://developer.android.com/reference/android/graphics/Bitmap.html
Upvotes: 1