You have 3 choice depending on what JDK you are using.
In all cases you will need to create a BufferedImage and write to it's Graphics2D obect. Once you have that.
If you are using JDK 1.2 or 1.3 it is more difficult. You will need to look at the com.sun.image.codec.jpeg package.
After you look at that you will want to focus on two classes JPEGImageEncoder, and JPEGEncodeParam. Plus you will need a ByteArrayOutputSteam, and a FileOutputStream.
Next, if you have JDK 1.4 you can do what I think is the easest method. You will need to look at the javax.imageio package. All you need from there is the ImageIO class. it has a write method that takes a RenderedImage (which is what a BufferedImage is), you give it the formate type (example "jpg" "gif" and a OutputStream. Your done.
The last way is with Sun's Advanced Imaging API. This one is similar to the first one in how you do it. The problem is that it is a external library not part of the J2SE. You would have to download this from Sun, and then look at the javax.imageio package. Focus on the ImageEncoder and JPEGEncodeParam classes. You will need a FileOutputStream here as well.
I recommend the 2nd way using JDK 1.4 if you are or can use this JDK great.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.