7 Replies Latest reply on Feb 13, 2012 5:01 PM by 916969

    Why is the size of new image constructed using Bufferd Image class less?

      I am trying to compress image losslessly, for start I what I am doing is:
      step1. Access pixels of .jpg image and store in array
      Step2. Reconstruct the image from same array

      What I have found is, that the size of new image constructed is less than the original.
      I am pasting the code below

      public static void main(String[] args) {

      BufferedImage sourceImage = null;
      try {
      sourceImage = ImageIO.read(new File("Sample.jpg"));
      } catch (IOException e) {

      int type = sourceImage.getType();
      int w = sourceImage.getWidth();
      int h = sourceImage.getHeight();
      byte[] pixels = null;
      if (type == BufferedImage.TYPE_3BYTE_BGR) {
      pixels = (byte[]) sourceImage.getData().getDataElements(0, 0, w, h, null);
      try {
      BufferedImage edgesImage = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
      edgesImage.getWritableTile(0, 0).setDataElements(0, 0, w, h, pixels);
      ImageIO.write(edgesImage, "jpg", new File("result.jpg"));
      } catch (IOException e) {

      Please could any one explain me why is it so?