Bitmap. Save (imgpath, imageformat. JPEG );
// This is a part of the thumbnail.
Code The imageformat. JPEG file must not be omitted. Even if the saved file is in JPG format, it cannot be removed. If removed, the generated thumbnail is larger than the original image!
// In addition, imgpath must be created first; otherwise, a general error of GDI + will be generated.
Path = system. Web. httpcontext. Current. server. mappath (PATH );
Use if (! System. Io. Directory. exists (PATH) system. Io. directiory. createdirectory (PATH );
// Generate a thumbnail. Do not use the getthumbnailimage method. This method produces extremely bad thumbnails and cannot be used!
// The simple code is as follows:
String Path = system. Web. httpcontext. Current. server. mappath (strpath );
Sourcepath = system. Web. httpcontext. Current. server. mappath (sourcepath );
If (! System. Io. Directory. exists (PATH) system. Io. Directory. createdirectory (PATH );
String sourceimage = sourcepath + filename;
String thumbimage = path + filename;
// Source image (reference)
Image IMG = image. fromfile (sourceimage, true );
// Actual thumbnail size
System. Drawing. Size size = pic. imgsize (maxw, maxh, IMG. Width, IMG. Height );
Int W = size. width;
Int H = size. height;
// Draw a thumbnail
Bitmap bitmap = new Bitmap (W, H );
Graphics G = graphics. fromimage (Bitmap );
// Set the thumbnail rendering quality
G. compositingquality = system. Drawing. drawing2d. compositingquality. highquality;
G. smoothingmode = system. Drawing. drawing2d. smoothingmode. highquality;
// G. interpolationmode = system. Drawing. drawing2d. interpolationmode. highqualitybicubic;
// Clean the background
G. Clear (color. White );
Rectangle thumbrect = new rectangle (0, 0, W, H );
G. drawimage (IMG, thumbrect );
// Save the thumbnail
Bitmap. Save (thumbimage, imageformat. JPEG );
// Release the memory
Bitmap. Dispose ();
IMG. Dispose ();
G. Dispose ();