string newfilename="";
string fullname = FileUpload1.FileName.ToString();
string fn = DateTime.Now.ToString("yyyyMMddHHmmss") + fullname;
string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1);
if (typ2 == "gif" || typ2 == "jpg" || typ2 == "bmp" || typ2 == "png")
{
FileUpload1.SaveAs(Server.MapPath("../photo") + "//" + fn); //将文件保存在跟目录的UP文件夹下
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("../photo") + "//" + fn); //加文字水印,注意,这里的代码和以下加图片水印的代码不能共存
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("Verdana",12);
Brush b = new SolidBrush(Color.Red);
string addText = "自己随便加个什么字都行";
g.DrawString(addText, f, b, 5, 5);
g.Dispose();
newfilename="new_"+fn;
image.Save(Server.MapPath("../photo") + "//" + newfilename);
image.Dispose();
//生成新图片后删除上传时的图片
System.IO.File.Delete(Server.MapPath("../photo/"+fn));
}
else
{
JScript.JScript.Alert("文件类型不支持");
}