How to save the cropped image given the original image and the coordinates to crop

we are using java 1.3 for developing a j2ee application using struts framework.to upload the photo i am using <html:file> tag in the jsp. Only jpegs are accepted.
after uploading the photo, there is a option for cropping. in the front end, i am using Prototype JavaScript Image Cropper UI. a demo is available on net. the link is

http://www.defusion.org.uk/demos/060519/cropper.php?demoType=preview&image=castle&formSubmit=Load+demo

using the tool, i can get the coordinates of the selected area.i am sending this coordinates to my action. After this point, i am stuck.

I have the original photo saved on the server. I have the coordinates of the cropped area. now i have to create a new photo(cropped photo) from the original photo. please help me to create the cropped photo and save on save on the server.
I can not use ImageIO since i am using java 1.3 version
can not use Swing since its a J2ee application
Dont want to use applets since the UI is already done and all that i want is to create a new jpeg file to save the cropped image. kindly help.
divyasindhuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
See https://jaistuff.dev.java.net/code/operators.Crop.html Ignore the Swing stuff - it's just for demo purposes

JAI is usable with JDK >= 1.3.
0
divyasindhuAuthor Commented:
JAI is not part of core Java. I do not want to install it. Hence i managed to solve it using BufferedImage. Here is the code which might be useful for other users:

import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

......
......
......
FileInputStream in = new FileInputStream("E:\\sample.jpg");
FileOutputStream op = new FileOutputStream("E:\\cropped.jpg");
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(op);

BufferedImage bufImage = decoder.decodeAsBufferedImage();
BufferedImage cropped = bufImage.getSubimage(10,20,40,30);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(cropped);
encoder.encode(cropped, param);

in.close();
op.close();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
It's probably better to use classes that are supported than ones that are not, and are also undocumented
0
divyasindhuAuthor Commented:
I do agree with you. But we can not change our environment. So we had to follow this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.