// <Summary>
/// Generate a thumbnail
/// </Summary>
/// <Param name = "fileName"> original file </param>
/// <Param name = "width"> width </param>
/// <Param name = "height"> height </param>
Private void CreateThumbnailImage (string fileName, string smallPath, int width, int height)
{
// Copyright information
String strAdd = "www.wandre.com ";
// The Name Of The generated thumbnail = year, month, and day + file size (to prevent identical file names)
String newFileName = smallPath;
System. Drawing. Image image, newImage;
// Load the original image
Image = System. Drawing. Image. FromFile (Server. MapPath (fileName ));
// Callback
System. Drawing. Image. GetThumbnailImageAbort callb = new System. Drawing. Image. GetThumbnailImageAbort (callBack );
// Generate a thumbnail
NewImage = image. GetThumbnailImage (width, height, callb, new System. IntPtr (); AddInfo (newImage, strAdd, newFileName, 16 );
Image. Dispose ();
NewImage. Dispose ();
Image1.ImageUrl = newFileName;
}
/// <Summary>
/// Add copyright information
/// </Summary>
/// <Param name = "image"> </param>
/// <Param name = "strAdd"> </param>
/// <Param name = "newFileName"> </param>
/// <Param name = "fontSize"> </param>
Private void AddInfo (System. Drawing. Image image, string strAdd, string newFileName, int fontSize)
{
Response. Clear ();
Bitmap B = new Bitmap (image );
Graphics g = Graphics. FromImage (B );
G. DrawString (strAdd, new Font ("", fontSize), new SolidBrush (Color. Red), image. Width/2-80, image. Height-30 );
B. Save (Server. MapPath (newFileName), System. Drawing. Imaging. ImageFormat. Gif );
}
Private bool callBack ()
{
Return true;
}
Protected void button#click (object sender, EventArgs e)
{
If (loadFile. PostedFile! = Null)
{
// Determine whether it is an image file
If (loadFile. PostedFile. ContentType. ToLower (). IndexOf ("image") <0)
{
// File type error
}
Else
{
String ext = loadFile. PostedFile. FileName. Substring (loadFile. PostedFile. FileName. LastIndexOf ("."));
// Generate a new original file name year month day + file size + Extension
String path = "Uploads \" + System. DateTime. Now. Date. to1_datestring () + loadFile. PostedFile. ContentLength. ToString () + ext;
// File with copyright information added
String newPath = "Uploads \" + System. DateTime. Now. Date. tow.datestring () + loadFile. PostedFile. ContentLength. ToString () + "new" + ext;
// Thumbnail file name
String newFileName = "uploads \" + System. DateTime. Now. Date. tow.datestring () + loadFile. PostedFile. ContentLength. ToString () + "small.gif ";
// Upload the source Image
LoadFile. PostedFile. SaveAs (Server. MapPath (path ));
// Generate a thumbnail
CreateThumbnailImage (path, newFileName, 200,300 );
// Add copyright information to the source Image
System. Drawing. Image image = System. Drawing. Image. FromFile (Server. MapPath (path ));
AddInfo (image, "www.wandre.com", newPath, 20 );
Image. Dispose ();
}
}
}