Import Java. AWT. graphics2d; import Java. AWT. image; import Java. AWT. mediatracker; import Java. AWT. geom. affinetransform; import Java. AWT. image. affinetransformop; import Java. AWT. image. bufferedimage; import Java. io. file; import Java. io. ioexception; import Java. util. iterator; import javax. imageIO. iioimage; import javax. imageIO. imageIO; import javax. imageIO. imagetypespecifier; import javax. imageIO. imagewriteparam; import javax. imageIO. imagewriter; import javax. imageIO. stream. imageoutputstream; import javax. swing. jpanel; public class rotateimage extends jpanel {image; bufferedimage bufimage; // buffer image for display bufferedimage originalbufimage; // original buffer image graphics2d bufimageg; // public void LoadImage (string filename) {image = This. gettoolkit (). getimage (filename); // obtain the image mediatracker Mt = new mediatracker (this); // instantiate the media loader Mt. addimage (image, 0); // Add the image to the loader. Try {Mt. waitforall (); // wait for image loading} catch (exception ex) {ex. printstacktrace (); // output error message} originalbufimage = new bufferedimage (image. getwidth (this), image. getheight (this), bufferedimage. type_int_argb); // create the original buffer image bufimage = originalbufimage; bufimageg = bufimage. creategraphics (); // create a bufimage graphical environment bufimageg. drawimage (image, 0, 0, this); // transmit source image data to the buffer image} // filter the image public void ratoteimage (INT angle) {If (bufimage = NULL) return; // If the bufimage is null, bufferedimage filteredbufimage = new bufferedimage (image. getwidth (this), image. getheight (this), bufferedimage. type_int_rgb); // The filtered image affinetransform transform = new affinetransform (); // The transform object transform. rotate (Java. lang. math. toradians (angle), image. getwidth (this)/2, image. getheight (this)/2); // rotate the image affinetransformop imageop = new affinetransformop (transform, null); // create the image op object of the affinetransformop operation. filter (originalbufimage, filteredbufimage); // filter the image. The target image is in filteredbufimagebufimage = filteredbufimage; // direct the buffer image used for display to the filtered image drawimg (bufimage );} public void drawimg (bufferedimage image) {imagewriter writer = NULL; imagetypespecifier type = imagetypespecifier. createfromrenderedimage (image); iterator iter = ImageIO. getimagewriters (type, "jpg"); If (ITER. hasnext () {writer = (imagewriter) ITER. next () ;}if (writer = NULL) {return;} iioimage = new iioimage (image, null, null); imagewriteparam Param = writer. getdefaultwriteparam (); Param. setcompressionmode (imagewriteparam. mode_explicit); Param. setcompressionquality (float) (1)/10.0); imageoutputstream outputstream; try {outputstream = ImageIO. createimageoutputstream (new file ("test.jpg"); writer. setoutput (outputstream); writer. write (null, iioimage, Param);} catch (ioexception e) {e. printstacktrace () ;}}/*** @ Param ARGs */public static void main (string [] ARGs) {rotateimage rotateimg = new rotateimage (); rotateimg. loadImage ("bm.jpg"); // load the image rotateimg. ratoteimage (90 );}}