C # can also generate a thumbnail (with Demo) for uploading images to the website Ajax)

Source: Internet
Author: User

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.