In getting Pixel
843829Mar 15 2005 — edited Apr 12 2005The following code is for converting grayscale image into array of pixels. This is working fine. I want to convert black and white image into array of pixels.
I tried...but not working.
Can any one help to get the array of pixels for BW image ?
LPBITMAPINFOHEADER lpbmih;
JNIEnv *env;
int width = lpbmih->biWidth;
int height = lpbmih->biHeight;
jintArray pixels = env->NewIntArray (width * height);
int palette = (int ) lpbmih + sizeof(BITMAPINFOHEADER);
int numColors;
if (lpbmih->biClrUsed > 0)
numColors = lpbmih->biClrUsed;
else
numColors = 1 << lpbmih->biBitCount;
unsigned char bitmap = (unsigned char ) lpbmih +
sizeof(BITMAPINFOHEADER) +
numColors * sizeof(RGBQUAD);
int padBytes = (4-width%4)%4;
jboolean isCopy;
jint *pixelsArray = env->GetIntArrayElements (pixels, &isCopy);
int rowBytes = width+padBytes;
for (int row = 0; row < height; row++)
for (int col = 0; col < width; col++)
{
int pixel = 0xff000000 | palette [bitmap [rowBytes*row+col]];
pixelsArray [width*(height-row-1)+col] = (jint) pixel;
}
if (isCopy == JNI_TRUE)
env->ReleaseIntArrayElements (pixels, pixelsArray, 0);
Thanks in advance,
Sri