Using system. IO;
Using system. Drawing. imaging;
Private void button#serverclick (Object sender, system. eventargs E)
{
Graphics G = NULL;
System. Drawing. Image upimage = NULL;
System. Drawing. Image thumimg = NULL;
System. Drawing. Image simage = NULL;
Bitmap outputfile = NULL;
Try
{
String extension = path. getextension (file1.postedfile. filename). toupper ();
String filename = datetime. Now. tostring ("yyyymmddhhmmss ");
String smallpath = server. mappath (".") + "/smallimg /";
String bigpath = server. mappath (".") + "/bigimg /";
Int width, height, newwidth, newheight;
System. Drawing. image. getthumbnailimageabort callb = new system. Drawing. image. getthumbnailimageabort (thumbnailcallback );
If (! Directory. exists (smallpath ))
Directory. createdirectory (smallpath );
If (! Directory. exists (bigpath ))
Directory. createdirectory (bigpath );
Stream upimgfile = file1.postedfile. inputstream;
String simagefile = server. mappath ("a8logo.jpg"); // the file to be watermarked
Simage = system. Drawing. image. fromfile (simagefile );
Upimage = system. Drawing. image. fromstream (upimgfile); // uploaded Image
Width = upimage. width;
Height = upimage. height;
If (width> height)
{
Newwidth = 200;
Newheight = (INT) (double) height/(double) width * (double) newwidth );
}
Else
{
Newheight = 200;
Newwidth = (INT) (double) width/(double) height * (double) newheight );
}
Thumimg = upimage. getthumbnailimage (newwidth, newheight, callb, intptr. Zero );
Outputfile = new Bitmap (upimage );
G = graphics. fromimage (outputfile );
G. drawimage (simage, new rectangle (upimage. width-simage.Width, upimage. height-simage.Height, upimage. width, upimage. height), 0, 0, upimage. width, upimage. height, graphicsunit. pixel );
String newpath = bigpath + filename + extension; // original graph path
String thumpath = smallpath + filename + extension; // thumbnail path
Outputfile. Save (newpath );
Thumimg. Save (thumpath );
Outputfile. Dispose ();
}
Catch (exception ex)
{
Throw ex;
}
Finally
{
If (G! = NULL)
G. Dispose ();
If (thumimg! = NULL)
Thumimg. Dispose ();
If (upimage! = NULL)
Upimage. Dispose ();
If (simage! = NULL)
Simage. Dispose ();
}
}
Public bool thumbnailcallback ()
{
Return false;
}