Package util;
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. Unzip codec;
Import com.sun.image.codec.jpeg. encode imageencoder;
Public class TuPian {
Public void jpgTset () throws Exception {
File _ file = new File ("d: ProjectTestpic11.jpg"); // read the File
Image src = javax. imageio. ImageIO. read (_ file); // construct an Image object
Int wideth = src. getWidth (null); // obtain the source image width.
Int height = src. getHeight (null); // obtain the source image length.
System. out. println ("Length:" + String. valueOf (wideth ));
System. out. println ("width" + String. valueOf (height ));
BufferedImage tag = new BufferedImage (wideth/2, height/2, BufferedImage. TYPE_INT_RGB );
Tag. getGraphics (). drawImage (src, wideth/2, height/2, null); // draw the reduced Graph
// Output to the file stream
FileOutputStream out = new FileOutputStream ("d: ProjectTestpic2newfile.jpg ");
// File file = new File ("newFile.jpg ");
Required imageencoder encoder = required codec. createJPEGEncoder (out );
Encoder. encode (tag); // JPEG encoding
Out. close ();
}
Public static void main (String [] args ){
Try {
New TuPian().jpg Tset ();
} Catch (Exception e ){
E. printStackTrace ();
}
}
}