title: Convert image into array of pixels, recreate image using pixels - size gets reduced. Why?
body: <p>I converted an image into an array of pixels. I saved RGB values in three seperate arrays. </p>
  
  <p>Then, I tried creating the image using the same values (no manipulation). Original image was of 205kB and the new image is of 121kB in case of B&amp;W image, and from 215kB to 96kB in case of colored image. Also, there is slight change in brightness (brightness gets increased and so does overall contrast). What is causing this?</p>
  
  <p>I have tried both with colored and B&amp;W images. Result was same.</p>
  
  <p>Also, I ran the same code on the previous output image (96kB), the new output was still 96kB.</p>
  
  <p><strong><em>Codes-</em></strong></p>
  
  <hr>
  
  <p><strong>1) To read image:</strong></p>
  
  <pre><code>int width = img.getWidth(null);
  int height = img.getHeight(null);
  
  pixelR = new int[width * height];
  pixelG = new int[width * height];
  pixelB = new int[width * height];
  
  int index=0;
  
  int r, g, b, gray, rgb;
  
  for(int i=0; i&lt;width; i++) {
    for (int j=0; j&lt;height; j++) {
      rgb = img.getRGB(i, j);
  
      r = (rgb &gt;&gt; 16) &amp; 0xFF;
      g = (rgb &gt;&gt; 8) &amp; 0xFF;
      b = (rgb &amp; 0xFF);
  
      pixelR[index]=r;
      pixelG[index]=g;
      pixelB[index]=b;
      index++;
    }
  }
  </code></pre>
  
  <p><strong>2) Write image:</strong></p>
  
  <pre><code>     BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  
    int index=0;
    int val;
    int r, g, b;
  
    for (int i=0; i&lt;width; i++) {
      for (int j=0; j&lt;height; j++) {
  
        r=pixelR[index];
        g=pixelG[index];
        b=pixelB[index++];
  
        Color newColor = new Color((int)r, (int)g, (int)b);     
        image.setRGB(i, j, newColor.getRGB());
      }
    }
  
    File f = null;
  
    try{
      f = new File("&lt;filepath&gt;.jpg");
        ImageIO.write(image, "jpg", f);
      }catch(IOException e){
        System.out.println("Error: "+e);
      }
    }
  </code></pre>