I have been thinking about it for the past two days and decided to sort out the small functions in my previous projects and offer them to everyone! After everyone's suggestion, I decided to add the source code, but the source code is not necessarily written by me. Some of the source code comes from books, some from the Internet, and some from open source projects. If it is inconsistent with my own code, then That’s the previous example!
Source code: smallImg.rar
The following is an 800*1000 image uploaded to generate different thumbnail
namespaces:
using System.IO;
core code:
System.Drawing.Image.GetThumbnailImageAbort callb = null;
try
{
// Save to the specified folder
File1.PostedFile.SaveAs(Server.MapPath("/semir/ImgSides/") + sidePath);
MyImage = System.Drawing.Image.FromFile(Server.MapPath("/semir/ImgSides/") + sidePath);
//Save the large image (original image)
NewImage = MyImage.GetThumbnailImage(800, 1000, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "big" + sidePath);
//Save the image
NewImage = MyImage.GetThumbnailImage(400, 500, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "middle" + sidePath);
// Image size of a single style of clothing
NewImage = MyImage.GetThumbnailImage(255, 319, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "SingleImage" + sidePath);
//Save thumbnail
NewImage = MyImage.GetThumbnailImage(115, 144, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "small" + sidePath);
//Save minimal image
NewImage = MyImage.GetThumbnailImage(45, 56, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "dinky" + sidePath);
MyImage.Dispose();
NewImage.Dispose();
// Must be released, otherwise the process will be occupied
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}