public void AddWaterPic() { //图片水印
string bg = Request.MapPath("~/images/bg.jpg");//背景图 string newPath = Request.MapPath("~/newImages/");//保存路径 string shuiyin= Request.MapPath("~/images/scrollBlock.jpg");//水印图片 System.Drawing.Image image = System.Drawing.Image.FromFile(bg); //取出背景图片 System.Drawing.Image img = System.Drawing.Image.FromFile(shuiyin);//取出水印图片 Graphics g = Graphics.FromImage(image); Rectangle rectbg = new Rectangle(932, 728, image.Width, image.Height); //水印的坐标宽932,高728 g.DrawImage(img, rectbg , 0, 0, img.Width, img.Height, GraphicsUnit.Pixel); //在指定位置并且按大小绘制水印图片
//文字水印 DateTime dt = Convert.ToDateTime(Date); g.DrawString(dt.ToString("yyyy年MM月dd日"), f, b, 934, 730); newImageName = (dt.ToString("yyyyMMddhhmmssms") + ".jpg"); System.Drawing.Image cover = System.Drawing.Image.FromFile(newPath + newImageName); Response.ContentType = "image/jpeg";//设置输出类型为JPEG图片 cover.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//将修改的图片存入输出流 cover.Dispose();//输出图片到客户端 Response.End(); }
asp.net 图片水印+文字水印,布布扣,bubuko.com
原文:http://www.cnblogs.com/Yashull/p/3701419.html