0

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);
        } 


  }
Barett
  • 5,826
  • 6
  • 51
  • 55
Poles
  • 3,585
  • 9
  • 43
  • 91
  • 1
    That's a lot 'o code, and I don't think 100% of it is necessary. Might make it easier to answer if you're able to strip it down to just the relevant bit? (like the `cropImage` method I think?) – Paul Richter Sep 26 '13 at 14:12
  • 1
    You may be able to adapt one of the approaches shown [here](http://stackoverflow.com/q/15961412/230513). – trashgod Sep 26 '13 at 15:37
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Sep 26 '13 at 16:22

0 Answers0