Import Java. io. file; <br/> Import Java. io. fileoutputstream; <br/> Import Java. AWT. color; <br/> Import Java. AWT. graphics; <br/> Import Java. AWT. image; <br/> Import Java. AWT. image. bufferedimage; <br/> Import com.sun.image.codec.jpeg. export codec; <br/> Import com.sun.image.codec.jpeg. required imageencoder; </P> <p> public class jpgtest {</P> <p> Public void jpgtset () throws exception {<br/> file _ file = new file ("D:/temp/11.jpg"); // read the file <br/> image src = javax. imageIO. imageIO. read (_ file); // construct an image object <br/> int width = SRC. getwidth (null); // obtain the source image width. <br/> int Height = SRC. getheight (null); // obtain the source image length </P> <p> // length required <br/> int newwidth = 22; // width/2 <br/> int newheight = 22; // height/2 <br/> bufferedimage image = new bufferedimage (newwidth, newheight, <br/> bufferedimage. type_int_rgb); <br/> graphics = image. getgraphics (); </P> <p> graphics. drawimage (SRC, 0, 0, newwidth, newheight, null); // draw a thumbnail <br/> // draw a border after drawimage, the following <SPAN class = 'wp _ keywordlink '> Code </span> adds two pixels of white edges to the image <br/> graphics. setcolor (color. white); <br/> graphics. drawrect (0, 0, newwidth-1, newheight-1); <br/> graphics. drawrect (1, 1, newwidth-1, newheight-1); <br/> graphics. drawrect (0, 0, newwidth-2, newheight-2); </P> <p> fileoutputstream out = new fileoutputstream ("D:/temp/44.jpg "); // output to the file stream <br/> export imageencoder encoder = export codec. createjpegencoder (out); <br/> encoder. encode (image); // JPEG encoding <br/> out. close (); <br/>}< br/> Public static void main (string [] ARGs) {<br/> jpgtest JPG = new jpgtest (); <br/> try {<br/> JPG. jpgtset (); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}< br/>}