title: How to Read JPEG image into BufferedImage object using Java
body: <p>This is not a duplicated question here, because I've been searching for the solution for a long time in Google and StackOverflow, and still cannot find a solution.</p>
  
  <p>I have these two images:</p>
  
  <p><img src="https://i.stack.imgur.com/6jfMK.jpg" alt="Larger Image"></p>
  
  <p><img src="https://i.stack.imgur.com/uFjUr.jpg" alt="Smaller Image"></p>
  
  <p>These are two images from the same website with same prefix and same format. The only difference is the size: the first is larger, while the second is smaller.</p>
  
  <p>I downloaded both of the images to local folder and used Java to read them into BufferedImage objects. However, when I outputted the BufferedImages to local files, I found that the first image was almost red, while the second was normal(same as original). What's wrong with my code?</p>
  
  <pre><code>byte[] rawData = getRawBytesFromFile(imageFilePath); // some code to read raw bytes from image file
  ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(rawData));
  BufferedImage img = ImageIO.read(iis);
  FileOutputStream fos = new FileOutputStream(outputImagePath, false);
  ImageIO.write(img, "JPEG", fos);
  fos.flush();
  fos.close();
  </code></pre>
  
  <p>PS: I used GIMP to open the first image and detected that the Color Mode is 'sRGB', no alpha or other stuff.</p>