Reputation: 619
I can read in an image and write to an image and the image looks perfect. So thats ok.
I think I am having difficulties with my bit shifting. Because when I test print the first 3 RGB int values, and then test print the 3 int values after, they don't have the same values? But the I run the program again, the first print values are the same as the first print values before?
OK, below is the code when I bit shift the values out into red, green and blue arrays
int g=0;
for(int row=0; row<h; row++)
{
for(int col=0; col<w; col++)
{
redPixels[row][col] = ((RGBarray[g]>>16)&0xff);
greenPixels[row][col] = ((RGBarray[g]>>8)&0xff);
bluePixels[row][col] = (RGBarray[g]&0xff);
g++;
}
}
Below is the code to bit shift the values back into integers...
for(int row=0; row<h; row++)
{
for(int col=0; col<w; col++)
{
int rgb = (redPixels[row][col] & 0xff) << 16 | (greenPixels[row][col] & 0xff) << 8 |(bluePixels[row][col] & 0xff);
bufferedImage.setRGB(col, row, rgb);
}
}
first 3 int values before bit shifting into array: -16573912 -16573912 -16508119
first 3 int values after bit shifting back into integers: 203304 203304 269097
But keep in mind, when I run the program again, the exact same values are shown (in this case the above same output). And also that an accurate image is created. I am just unsure about the values not being the same before and after bit shifting?
Hope this is clear? Thanks
Upvotes: 2
Views: 139
Reputation: 53664
Your RGB values are 24 bits (3*8), but a java int is 32 bits. if you look at the hexidecimal values, the difference should be more obvious:
-16573912 = 0xFF031A28
203304 = 0x00031A28
Upvotes: 3