I'm fairly new to programming on the android platform. I'm having some problems massaging an int array to turn it into a Bitmap.
Each element in the int array is a number from 0 to 255, and represents a grey-scale pixel color (so 0 would be black, and 255 would be white, etc...). Here's my code:
int nPixels = 262144;
int width = 512;
int height = 512;
int[] converted = new int[nPixels];
int alpha = 255;
for (int i = 0; i < nPixels; i++) {
//greyscale, so all r, g, and b have the same value
converted[i] = (alpha << 24) | (pixels[i] << 16) | (pixels[i] << 8) | pixels[i];
}
Bitmap bm = Bitmap.createBitmap(converted, width, height, Bitmap.Config.ARGB_8888);
The resulting bitmap has height and width of -1, which indicates that the createBitmap function didn't work. What is wrong with my method?
Oh, I took the shifting part for making the color from http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.html.
Edit: thought it might've been because alpha was 256 instead of 255, but I still get the same error.