Skip to content

Instantly share code, notes, and snippets.

@catehstn
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catehstn/9742403ae95bb7894918 to your computer and use it in GitHub Desktop.
Save catehstn/9742403ae95bb7894918 to your computer and use it in GitHub Desktop.
/**
* A image from an array of colors.
* @param width
* @param height
* @param colors
* @return image of given width and height filled with the given color array.
*/
public static Bitmap createImage(int width, int height, int[] colors) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int x = 0;
int y = 0;
for (int color : colors) {
bitmap.setPixel(x, y, color);
x++;
if (x == width) {
x = 0;
y++;
}
}
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment