import java.awt.*; import java.applet.*; import java.util.*; import java.io.*; import java.awt.event.*; import java.awt.image.*; import com.sun.image.codec.jpeg.*; import java.awt.*; import javax.swing.*; public class createNewImageFromOldImage extends JApplet { Image img; BufferedImage theimagethatisbuffered = null; String status = new String(" "); String In_Image = new String(" "); String Out_Image = new String(" "); public createNewImageFromOldImage() { } public String copyImage(String ImageIn, String ImageOut) { /////////////////////////////////////////////// Toolkit toolkit = Toolkit.getDefaultToolkit(); img = toolkit.getImage(ImageIn); // First, create a new BufferedImage area... try { MediaTracker tracker = new MediaTracker(this); tracker.addImage(img, 0); tracker.waitForID(0); } catch (Exception e) { status = "0"; } // Then draw the previous Image img onto this BufferedImage area int width = img.getWidth(this); int height = img.getHeight(this); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D biContext = bi.createGraphics(); biContext.drawImage(img, 0, 0, null); theimagethatisbuffered = bi; // Set the name of the new image file to be created String thenewimageFiletoBeCreated = ImageOut; try { // Create a new output stream for the new image FileOutputStream outstream = new FileOutputStream(thenewimageFiletoBeCreated); // Use the JPEGImageEncoder class to set the name of the new image to be encoded JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outstream); // Create the new JPEG image by encoding the previously loaded Image img file encoder.encode(theimagethatisbuffered); // Flush and Close the ouput stream buffer outstream.flush(); outstream.close(); status = "1"; } catch (Exception exc) { exc.printStackTrace(); status = "0"; } return status; } //*************** // Main method //*************** public static void main (String args[]) { createNewImageFromOldImage s = new createNewImageFromOldImage(); String oldimage, newimage; oldimage = args[0]; newimage = args[1]; s.copyImage(oldimage, newimage); } }