Using System.IO;
Using System.Drawing.Imaging;
private void Button1_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"); File to be added to the watermark
Simage=system.drawing.image.fromfile (Simagefile);
Upimage= System.Drawing.Image.FromStream (Upimgfile); Uploaded pictures
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 Diagram 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;
}