0 Replies Latest reply: Dec 24, 2012 12:55 AM by 981450 RSS

    Wrong Out while Cropping image using different java version

    981450
      Hi,

      my task is to crop the image based on x,y,w,h coordinates, but thing is i am getting different cropped images while using java 1.6 and java 1.7.

      in java 1.6 the x and y coordinates starting from 0,0 instead of given values.

      please find the code below:

      -------------------------------------------

      import java.awt.Image;
      import java.awt.image.BufferedImage;
      import java.io.File;

      import javax.imageio.ImageIO;

      public class CropImage {
      Image image;
      // Insets insets;
      BufferedImage img = null;

           
           public CropImage(){
                
                try{
      img = ImageIO.read(new File("D:/temp/","Capture.gif"));

      File outputfile = new File("D:/temp/","saved.gif");
      // 49,158,58,7 -x,y,w,h

      ImageIO.write(img.getSubimage(58, 6, 158, 50), "gif", outputfile);

                }catch(Exception es){
                     es.printStackTrace();
                }

                
           }
           
           public static void main(String args[]){
                new CropImage();
           }
           

      }
      ------------------------------------------------------------------


      Thanks,
      shashanka.

      Edited by: user8956018 on Dec 23, 2012 10:54 PM