I use class PixelGrabber to get a two-value bitmap’s pixel array. But one problem comes out, a two-value image(white or black), I stored these pixels of the bitmap in a int array, these elements of the array shouldn’t be 1(white) or 0(black) but in my code I find white is -1 and black is -16777216. Anyone know why?
Now I would like to just simply use a for loop to change -1 and -16777216 to 1 and 0.
I’m assuming that you’re using the
PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize)constructor, in which case what you’re getting back is an integer array of the RGB value of each pixel.Because it’s coming back as an RGB value – you need to seperate out the values to give you a true RGB value. For example RGB(255,255,255) is White and RGB(0,0,0) is black. The API Reference gives a good example of how to do this properly. With the
-16777216number in your question, I performed a simple test which shows that it is actually black:Follow the API reference linked above for example code of how to handle the pixel data correctly.