0

I'm trying to get the 16-bit integer unsigned value for a pixel in an image using JAVA. I'm using:

int d = img.getRGB(x, y);

I get numbers like this -16744032, I don't think that getRGB is the right method to use, along with that it is signed.

Note: I don't want to convert it to RGB.

all that I want is: 16-bit Integer unsigned value for a pixel.

UPDATE: what I want is not a very complicated method that has nothing to do with colors at all.

Yousef
  • 450
  • 6
  • 13
  • And that unsigned 16 bits represent what exactly? – dhke Oct 03 '17 at 07:48
  • Possible duplicate of [How to convert signed 16 bit integer to unsigned 16 bit integer in Java?](https://stackoverflow.com/questions/28707317/how-to-convert-signed-16-bit-integer-to-unsigned-16-bit-integer-in-java) – fantaghirocco Oct 03 '17 at 07:48

1 Answers1

0

I don't have experience with image manipulation in java, but from the javadoc you should be able to get a Raster object from the method getRaster(), then either getPixel(x,y,int[] arr) or getDataElements(x,y,object outData) may work.

That assumes that the image is in 16 bits format in the first place. If not you will need to convert the RGB value to 16 bits. This question may be relevant in that case: How to convert between color models

Sources: https://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html#getRaster() https://docs.oracle.com/javase/7/docs/api/java/awt/image/Raster.html

ggf31416
  • 3,582
  • 1
  • 25
  • 26