asp.net 图片水印+文字水印

时间:2014-05-01 12:06:51   收藏:0   阅读:350

 

bubuko.com,布布扣
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(); }   
bubuko.com,布布扣

 

asp.net 图片水印+文字水印,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!