C # a thumbnail Generation Program
If (fileupload. PostedFile! = Null)
{
// Addto is the attribute to be added, and aboutfile is the file description.
String nam = fileupload. PostedFile. FileName;
// Obtain the index of the last "." In the file name (including the path)
Int I = nam. LastIndexOf (".");
// Get the file extension
String newext = nam. Substring (I );
// Here, I automatically name the File Based on the date and file size to ensure that the file name is not repeated
DateTime now = DateTime. Now;
String newname = now. DayOfYear. ToString () + fileupload. PostedFile. ContentLength. ToString ();
// Save the file to the directory you want. This is the upload directory under the IIS root directory. You can change it.
// Note: Server is used here. ath () obtains the relative directory of the current file. in asp.net, "/" must be replaced by "//". Changing "upload/" to "// upload/" becomes the absolute directory of the current file.
Fileupload. PostedFile. SaveAs (Server. MapPath ("upload //" + newname + newext ));
// Obtain the relevant attributes of the file: file name, file type, and file size.
// Fname. Text = myFile. PostedFile. FileName;
// Fenc. Text = myFile. PostedFile. ContentType;
// Fsize. Text = myFile. PostedFile. ContentLength. ToString ();
// Below is the thumbnail generated
System. Drawing. Image image, aNewImage;
Int width, height, newwidth, newheight;
Image = System. Drawing. Image. FromFile (Server. MapPath ("upload/" + newname. ToString () + newext. ToString ()));
System. Drawing. Image. GetThumbnailImageAbort callb = new System. Drawing. Image. GetThumbnailImageAbort (ThumbnailCallback );
Width = image. Width;
Height = image. Height;
If (firstpageshow. SelectedValue. ToString () = "1" & fenlei. SelectedValue. ToString () = "5 ")
{
Newwidth = 203; newheight = 86;
Newheight = height * newwidth/width;
}
Else if (isweekman. SelectedValue. ToString () = "1 ")
{
Newwidth = 171; newheight = 111;
Newheight = height * newwidth/width;
}
Else if (firstpageshow. SelectedValue. ToString () = "1" & fenlei. SelectedValue. ToString () = "3 ")
{
Newwidth = 171; newheight = 111;
Newheight = height * newwidth/width;
}
Else
{
Newwidth = 62; newheight = 80;
Newheight = height * newwidth/width;
}
ANewImage = image. GetThumbnailImage (newwidth, newheight, callb, new System. IntPtr ());
ANewImage. Save (Server. MapPath ("upload //" + "small _" + newname + newext ));
Image. Dispose ();
// After the thumbnail is generated and saved, a small _ is added before the source image name _.
Pic = "upload/" + newname. ToString () + newext. ToString ();
Smallpic = "upload/small _" + newname. ToString () + newext. ToString ();