How to crop an image

Hi i am making a paint program and one of the tools i am stuck on is crop.i have got as far as the user being able to draw a rectangle and i can get the coordinates from it, but i dont know how to get the graphics enclosed in the coordinates to make an image...can anyone help?
[291 byte] By [boblettoj99a] at [2007-11-27 4:48:56]
# 1
If you can load the image as a java.awt.image.BufferedImage, there's a method to get a subimage.
bsampieria at 2007-7-12 10:01:56 > top of Java-index,Java Essentials,New To Java...
# 2
hmm ok ill try that
boblettoj99a at 2007-7-12 10:01:56 > top of Java-index,Java Essentials,New To Java...
# 3

If you are trying to crop or clip whatever you are rendering, you can play around with the graphics's object clip property though these methods:

java.awt.Graphics:

clipRect(x, y, width, height)

Shape getClip()

setClip(x, y, width, height)

setClip(Shape)

java.awt.Graphics2D:

clip(Shape)

Read the API for details.

Hippolytea at 2007-7-12 10:01:56 > top of Java-index,Java Essentials,New To Java...