0

我正在尝试缩放由以下人员拍摄的图像:

机器人.createScreenCapture(新矩形(x,y,area.getWidth(),area.getHeight()

但是在裁剪之后,当我将它放入 jLabel(高度:165px 和宽度:214)时,它会被拉伸和扭曲。临时文件夹中存储的图像很好。这是我的代码:

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


  }
4

0 回答 0