Import java.io.file;
Import java.io.fileoutputstream;
Import java.awt.graphics;
Import Java.awt.Image;
Import java.awt.image.bufferedImage;
import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; public class JpgTest {public void JpgTset () throws Exception {File _file = new File ( "/ Order005-0001. JPG "); // Read file image src = javax.imageio.Imageio.read (_file); // Construction image object int wideth = src.getWidth (null); // Get source map wide int Height = src.getHeight (NULL); // Get the source map long bufferedimage tag = new bufferedimage (wideth / 2, height / 2, bufferedimage.Type_INT_RGB); tag.getgraphics (). DrawImage (src, 0, 0, wideth / 2, height / 2 NULL); // Draw a reduced picture fileOutputStream out = new fileoutputstream ("newfile.jpg"); // Output to the file stream JPEGIMAGEENCODER ENCODER = JPEGCODEC.CREATEJPEGENCODER (OUT); Encoder.Encode (tag); // JPEG code //system.out.print(Width "8" ; out.close ();}} The process is very simple, from the local disk read file order005-0001.jpg (2032 * 1524), becomes an image object SRC, then construct the target file TAG, set the length of the TAG to half the source map, encoded TAG, output To the file stream OUT, close the file stream. There are still some questions that need to be explained: First, only three types of JPG (JPEG), GIF, PNG can be supported. Second, for the capacity of the source map, it is best not to exceed 1M, otherwise it will throw insufficient errors, but I tried 1.8M source map, which can be successful, but it is easy to throw instructions. Quote a senior: The image operation itself is a intensive operation, which requires a lot of memory amplifies. I tried it with VC, and the image of 4M also has problems, and the more compressed than large pictures are restored to Bitmap in memory. The larger. The method of solving can rewrote the encoding class, open a certain amount of memory first, and then write it in a temporary file, and then read it again. Or use the NIO's memory image to operate.