This might sound stupid, but "please" cope with me.
I got an image in jpg format which I want to read in an array or something (not sure)
I only want the bytes of the image, not the headers, size, thumb etc.
Basically what I'm trying to do is:
Read the image, change a few colors by changing the "bytes", & then save it.

On wickypedia it says that jpeg format begins with a 0xFF byte, but I'm not able to find this in the images I read. All I get is numbers, symbols etc...

Here's my code so far (totally idiotic)

InputStream in = new FileInputStream("test_file.jpg");
Reader reader = new InputStreamReader(in);
int r; byte b; char c;
while ((r = reader.read()) != -1){
b= (byte) r; c= (char) r;
System.out.println(" "+ b + " , " + r + " , " + c );
}catch (Exception e){ }

Am I missing something here, or is it totally in opposite direction?
Do I need to decompress/unzip the image data before reading it, or something else?

Please help me.
Thank you

Fortunately Sun/Oracle have already written 99% of the code you need. It's all in the standard API.
Use the ImageIO class to read the file into memory, ImageIO will handle all the details of decompressing the jpeg for you.That gives you an in-memory BufferedImage, so you can use its getRGB and setRGB methods to access or update individual pixels. See the Java API doc for details.

Billion thanks!!!
I tried the javax.imageio API & the hard part is already done!
Thank you so much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.