Code segment 1
======================================
System. Drawing. Image image =
System. Drawing. image. fromfile (originalfilename );
System. Drawing. Size size = getimagesize (image. Width, image. height,
Information. maximumdimension );
System. Drawing. Image bitmap = new system. Drawing. Bitmap (size. Width,
Size. Height );
System. Drawing. Graphics graphics =
System. Drawing. Graphics. fromimage (Bitmap );
Graphics. interpolationmode =
System. Drawing. drawing2d. interpolationmode. High;
Graphics. smoothingmode = system. Drawing. drawing2d. smoothingmode. highquality;
Graphics. Clear (information. backgroundcolor );
Graphics. drawimage (image, new system. Drawing. rectangle (0, 0, bitmap. Width,
Bitmap. Height), new system. Drawing. rectangle (0, 0, image. Width,
Image. Height), system. Drawing. graphicsunit. pixel );
Graphics. Dispose ();
Code Segment 2
======================================
// Original image name
String originalfilename = "C: \ 222.jpg ";
// Generated high-quality image name
String strgoodfile = "C: \ 222-small-good.jpg ";
// Generated low-quality image name
String strbadfile = "C: \ 222-small-bad.jpg ";
// Multiples of the zoom-out
Int iscale = 3;
// Obtain an image object from a file
System. Drawing. Image image = system. Drawing. image. fromfile (originalfilename );
// Obtain the image size
System. Drawing. Size size = new size (image. width/iscale, image. Height/iscale );
// Create a BMP Image
System. Drawing. Image bitmap = new system. Drawing. Bitmap (size. Width, size. Height );
// Create a canvas
System. Drawing. Graphics G = system. Drawing. Graphics. fromimage (Bitmap );
// Set a high quality Interpolation Method
G. interpolationmode = system. Drawing. drawing2d. interpolationmode. High;
// Set high quality and smooth Low Speed
G. smoothingmode = system. Drawing. drawing2d. smoothingmode. highquality;
// Clear the canvas
G. Clear (color. Blue );
// Draw a picture at a specified position
G. drawimage (image, new system. Drawing. rectangle (0, 0, bitmap. Width, bitmap. Height ),
New system. Drawing. rectangle (0, 0, image. Width, image. Height ),
System. Drawing. graphicsunit. pixel );
// Save high-definition thumbnails
Bitmap. Save (strgoodfile, system. Drawing. imaging. imageformat. JPEG );
// Obtain the common thumbnail of the original image
System. Drawing. Image IMG = image. getthumbnailimage (image. width/iscale, image. Height/iscale, null, intptr. Zero );
// Save common thumbnails
IMG. Save (strbadfile, system. Drawing. imaging. imageformat. JPEG );
G. Dispose ();
MessageBox. Show ("generated ");
A piece of source image + thumbnail code written by myself
====================================
Using system;
Using system. collections;
Using system. componentmodel;
Using system. configuration;
Using system. Data;
Using system. drawing;
Using system. Drawing. imaging;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Namespace bscrm. shangpin
{
/// <Summary>
/// Summary of shangpin_img.
/// </Summary>
Public class shangpin_img: system. Web. UI. Page
{
String ImagePath = configurationsettings. receivettings ["ImagePath"] + "\\";
Bool error;
String SRC;
Int height, width;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Height = width = 0;
If (request ["H"]! = NULL & request ["H"]. tostring (). Trim ()! = "")
{
Height = int. parse (request ["H"]. tostring (). Trim ());
}
If (request ["W"]! = NULL & request ["H"]. tostring (). Trim ()! = "")
{
Width = int. parse (request ["W"]. tostring (). Trim ());
}
If (request ["src"]! = NULL)
{
Src = ImagePath + request ["src"]. tostring ();
Try
{
System. Drawing. Image IMG = system. Drawing. image. fromfile (SRC );
If (height> 0 | width> 0)
{
If (Height = 0) Height = IMG. height;
If (width = 0) width = IMG. width;
System. Drawing. Image img2 = IMG. getthumbnailimage (width, height, null, intptr. Zero );
Img2.save (response. outputstream, IMG. rawformat );
Img2.dispose ();
}
Else
{
IMG. Save (response. outputstream, IMG. rawformat );
}
IMG. Dispose ();
}
Catch
{
Error = true;
}
}
Else
{
Error = true;
}
If (error)
{
Response. statuscode = 404;
Response. write ("<HTML> }
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the Asp.net web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}