-1

In my java project I need a method to convert an 8-bit (0,225) Grayscale image to a 3-bit one (0,7). Any ideas?

I used this method but it gives me

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!

image.getRaster().setSample(x, y, image.getRaster().getSample(x,y, 0)/32) 
lokusking
  • 7,396
  • 13
  • 38
  • 57
  • 1
    The phrase "doesn't work" doesn't tell us much. You may find this helpful: [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask). – MJH Oct 09 '16 at 00:57
  • Changing a sample to use fewer bits doesn't actually change the image to be a 3-bit grayscale image. The image databuffer is still the same bits-per-pixel as before. --- If you want to keep approximate pixel "color" (gray-level), you should clear the lower bits, not shift the bits, so use `sample = sample & 0xE0`. – Andreas Oct 09 '16 at 01:04

1 Answers1

0

I think you simply forgot that dividing by 32 isn't going to give you an integer. Try to parse that value to an INTEGER, and it might (or not) solve your issue.

Since the error is regarding array size, be sure you are not going out of the limits of image length and height.

Canilho
  • 944
  • 5
  • 11