How do I crop an image in Java?

前端 未结 7 1332
逝去的感伤
逝去的感伤 2020-11-29 00:22

I want to crop an image manually using the mouse.
Suppose the image has some text, and I want to select some text from an image, then for that purpose I want to crop th

7条回答
  •  离开以前
    2020-11-29 00:54

    File fileToWrite = new File(filePath, "url");
    
    BufferedImage bufferedImage = cropImage(fileToWrite, x, y, w, h);
    
    private BufferedImage cropImage(File filePath, int x, int y, int w, int h){
    
        try {
            BufferedImage originalImgage = ImageIO.read(filePath);
    
            BufferedImage subImgage = originalImgage.getSubimage(x, y, w, h);
    
    
    
            return subImgage;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    

提交回复
热议问题