Image Class

H

hierholzer

I'm reading in a JPEG and I get the RGB array via

image.getRGB(...);

I modify the first eight pixels of the RGB array. Specifically,
I modify each pixels lower 4 bits.

The output is the following:
rgb[0] = 11111111111111001111111111110000
rgb[1] = 11111111111111001111111111110000
rgb[2] = 11111111111111111111111111110000
rgb[3] = 11111111111111111111111111110000
rgb[4] = 11111111111111111111111111110000
rgb[5] = 11111111111111111111111111110000
rgb[6] = 11111111111111111111111111110001
rgb[7] = 11111111111111111111111111110100

I used Integer.toBinaryString on each element.
I then use the setRGB method of the Image class:
image.setRGB(...);

So that my new RGB values are saved.
After this, I write out the image data to a new
image; however, after I read in this new image,
the first 8 elements of the RGB array are as
follows:

rgb[0] = 11111111111111101111111111111010
rgb[1] = 11111111111111101111111111111010
rgb[2] = 11111111111111101111111011111100
rgb[3] = 11111111111111101111111011111100
rgb[4] = 11111111111111011111111111111110
rgb[5] = 11111111111111011111111111111110
rgb[6] = 11111111111111011111111111111110
rgb[7] = 11111111111111011111111111111110

Note: I read in a JPEG and write out a JPEG.

Any idea for this discrepancy?
 
J

Joshua Cranmer

hierholzer said:
Note: I read in a JPEG and write out a JPEG.

Any idea for this discrepancy?

JPEG is a lossy format, so writing out to a JPEG file will not, in
general, guarantee that pixel values remain the same.

The most notable non-lossy format is PNG; GIF is also non-lossy, but it
is an indexed format, which means that you lose out if you have more
pixel values than can exist in the palette.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top