How do I crop an image in Java?

前端 未结 7 1364
逝去的感伤
逝去的感伤 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:41

    The solution I found most useful for cropping a buffered image uses the getSubImage(x,y,w,h);

    My cropping routine ended up looking like this:

      private BufferedImage cropImage(BufferedImage src, Rectangle rect) {
          BufferedImage dest = src.getSubimage(0, 0, rect.width, rect.height);
          return dest; 
       }
    

提交回复
热议问题