This article aims to share with you how to use the C # "ps image" in the project to generate a scaled-down diagram of the same proportion for the website. If you have any shortcomings, please note.
I. Technical Overview:
1. Ajax does not need to upload images any more. Please read this article for details. (Jquery + c # ashx)
2. C # Bitmap Processing System. Drawing.
3. The latest demo supports IE7, IE8, and FireFox.
Ii. How to Deal with thumbnail:
Core Method for generating a thumbnail:
CreateThumbnailPicture
/// <Summary>
/// Image thumbnail Processing
/// </Summary>
/// <Param name = "srcPath"> source image </param>
/// <Param name = "destPath"> Target Image </param>
/// <Param name = "width"> width </param>
/// <Param name = "height"> height </param>
Public static void CreateThumbnailPicture (string srcPath, string destPath, int width, int height)
{
// Obtain the Image object of the source Image based on the absolute path of the Image Disk
System. Drawing. Image img = System. Drawing. Image. FromFile (srcPath );
// Bmp: the thumbnail bitmap object to be created.
Bitmap bmp = new Bitmap (width, height );
// G: draws a bmp Graphics object.
Graphics g = Graphics. FromImage (bmp );
G. Clear (Color. Transparent );
// Initialize necessary parameters for the Graphics g object, which is easy to understand.
G. PixelOffsetMode = System. Drawing. Drawing2D. PixelOffsetMode. HighQuality;
G. InterpolationMode = System. Drawing. Drawing2D. InterpolationMode. High;
G. SmoothingMode = System. Drawing. Drawing2D. SmoothingMode. HighQuality;
G. CompositingQuality = System. Drawing. Drawing2D. CompositingQuality. HighQuality;
// Source image width and height
Int imgWidth = img. Width;
Int imgHeight = img. Height;
// Draw a thumbnail
G. DrawImage (img, new System. Drawing. Rectangle (0, 0, width, height), new System. Drawing. Rectangle (0, 0, imgWidth, imgHeight)
, GraphicsUnit. Pixel );
ImageFormat format = img. RawFormat;
ImageCodecInfo info = ImageCodecInfo. GetImageEncoders (). SingleOrDefault (I => I. FormatID = format. Guid );
EncoderParameter param