Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I crop an image in Java?

Tags:

java

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 that area by using the mouse.

like image 583
Hussain Avatar asked Mar 05 '10 10:03

Hussain


People also ask

What function can be used to crop an image in Java?

To crop an image in Java, just use the Java BufferedImage class, specifically the getSubimage method of the BufferedImage class.


1 Answers

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;     } 
like image 104
codehead Avatar answered Sep 21 '22 02:09

codehead