How to cut a portion of jpg file ?

I am new in Java Currently i am trying to develop an application that need to cut a portion of a map(whole map is a jpg file). Can anyone know how to do it? I havetried to figure it for weeks but still dun have any idea. Thanks in advance!
[254 byte] By [cheahwena] at [2007-9-30 1:21:11]
# 1
You could take a look at the CropImageFilter in java.awt.image........
borland3.1a at 2007-7-16 5:57:28 > top of Java-index,Other Topics,Algorithms...
# 2
Thanks.Can you show me an example of code pls?Thanks again!
cheahwena at 2007-7-16 5:57:28 > top of Java-index,Other Topics,Algorithms...
# 3

Here is some i scooped of the internet... supply a "test.gif" (small one, it displays the cropped pic at X = 70 and Y = 70, you can change that in the paint method if you'd like)

import java.applet.Applet;

import java.awt.*;

import java.awt.image.*;

public class CropImage extends Applet implements Runnable {

Image the_picture, cropped_picture;

boolean image_ready;

Thread the_thread;

MediaTracker the_tracker;

public void start() {

if (the_thread == null) {

the_thread = new Thread(this);

the_thread.start();

}

}

public void stop() {

the_thread.stop();

}

public void run() {

the_thread.setPriority(Thread.MIN_PRIORITY);

while (true) {

repaint();

try {

the_thread.sleep(3000);

} catch(InterruptedException e) {};

}

}

public void init() {

CropImageFilter c_i_filter;

//Define a MediaTracker to monitor the completion status of an image

//You need to supply a component as the argument.

//In this case the applet

// is used

the_tracker = new MediaTracker(this);

image_ready = false;

the_picture = getImage(getDocumentBase(),"test.gif");

//tell MediaTracker to monitor the progress of the image and

//assign the image

//the index of 0--the index value is arbitrary

the_tracker.addImage(the_picture,0);

//Define an image cropping filter

c_i_filter = new CropImageFilter(0,0,32,32);

//Apply the filter to the image and make a new image of the cropped area

cropped_picture = createImage(new FilteredImageSource(

the_picture.getSource(),c_i_filter));

//Monitor the cropped image to see when it's done

the_tracker.addImage(cropped_picture,1);

}

public void paint (Graphics g) {

//Wait till both images are ready

if(the_tracker.checkID(0,true) & the_tracker.checkID(1,true)) {

image_ready = true;

//g.drawImage(the_picture,0,0,this);

g.drawImage(cropped_picture,70,70,this);

} else {

System.out.println("Waiting for image to fully load");

}

}

}

borland3.1a at 2007-7-16 5:57:28 > top of Java-index,Other Topics,Algorithms...