string imgdate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Ticks.ToString();
//上传图片并生成缩略图150*150并添加文字水印
if (FUImg.PostedFile.FileName != string.Empty)
{
string imgtype = FUImg.PostedFile.FileName.Substring(FUUserImg.PostedFile.FileName.LastIndexOf("."));
string imgname = imgdate + imgtype;
FUImg.PostedFile.SaveAs(Server.MapPath("../*****") + @"/" + imgname);
System.Drawing.Image image, aNewImage;
image = System.Drawing.Image.FromStream(FUImg.PostedFile.InputStream);
decimal width = image.Width;
decimal height = image.Height;
int newwidth, newheight;
if (width > height)
{
newwidth = 150;
newheight = (int)(height / width * 150);
}
else
{
newheight = 150;
newwidth = (int)(width / height * 150);
}
aNewImage = image.GetThumbnailImage(newwidth, newheight, null, IntPtr.Zero);
Bitmap output = new Bitmap(aNewImage);
Graphics g = Graphics.FromImage(output);
g.DrawString("水印文字", new Font("Courier New", 14), new SolidBrush(Color.Red), 60, 60);//写版权信息及文本格式及位置
output.Save(Server.MapPath("../*****") + @"/s_" + imgname, System.Drawing.Imaging.ImageFormat.Jpeg);
}
上传图片 并生成缩略图 并添加文字水印
最新推荐文章于 2017-11-22 08:49:01 发布