Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

In getting Pixel

843829Mar 15 2005 — edited Apr 12 2005
The 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2005
Added on Mar 15 2005
4 comments
159 views