I am trying to scale a image taken by:
robot.createScreenCapture(new Rectangle(x,y,area.getWidth(),area.getHeight()
But after cropping, when I put it into a jLabel (Height:165px and Width:214) it gets stretched and distorted.where the stored image in temp folder is fine.Here is my code:
public void cropImage(){
try {
//Execute when button is pressed
//Point pt = resizer.getLocation();
// this.setVisible(false);
Robot robot= new Robot();
Point pt = this.resizer.getLocationOnScreen();
// int x = ((int)this.getLocation().getX()+1)+(int)pt.getX()+1;
// int y = ((int)this.getLocation().getY()+1)+(int)pt.getY()+1;
int x = (int)pt.getX()+1;
int y = (int)pt.getY()+1;
System.out.println("----------------------------");
System.out.println(" X : "+x +" Y : "+ y);
System.out.println("----------------------------");
System.out.println(" Width : "+area.getWidth() +" Height : "+ getHeight());
BufferedImage img = robot.createScreenCapture(new Rectangle(x,y,getWidth(),area.getHeight()));
String saveFilePath = Common.getTempPath()+Common.getSeparator()+"temp.jpg";
File save_path=new File(saveFilePath);
ImageIO.write(img, "JPG", save_path);
emf.createInsideElements(saveFilePath);
emf.repaint();
emf.pack();
this.dispose();
} catch (AWTException ex) {
Logger.getLogger(ResizableComponent.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ResizableComponent.class.getName()).log(Level.SEVERE, null, ex);
}
}