Jsp tutorial to generate a thumbnail code program
Java. io. File file = new java. io. File (saveurl); // read the uploaded File
String newurl = request. getRealPath ("/") + url + "min _" + filename + "." + ext; // New thumbnail storage address
Image src = javax. imageio. ImageIO. read (file); // construct an Image object
Float tagsize = 200;
Int old_w = src. getWidth (null); // Obtain the source image width.
Int old_h = src. getHeight (null );
Int new_w = 0;
Int new_h = 0; // Obtain the source image length.
Int temps tutorial ize;
Float tempdouble;
If (old_w> old_h ){
Tempdouble = old_w/tagsize;
} Else {
Tempdouble = old_h/tagsize;
}
New_w = Math. round (old_w/tempdouble );
New_h = Math. round (old_h/tempdouble); // calculate the length and width of the new graph.
BufferedImage tag = new BufferedImage (new_w, new_h, BufferedImage. TYPE_INT_RGB );
Tag. getGraphics (). drawImage (src, new_w, new_h, null); // draw the reduced graph
FileOutputStream newimage = new FileOutputStream (newurl); // output to the File Stream
Required imageencoder encoder = required codec. createJPEGEncoder (newimage );
Encoder. encode (tag); // near JPEG encoding
Newimage. close ();