程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c#添加水印效果

c#添加水印效果

編輯:C#入門知識

下面的代碼中 添加文字水印 和 圖片水印是不能共存的(下面寫在一起是為了方便顯示)

private void Btn_Upload_Click(object sender, System.EventArgs e)
        {
            if(UploadFile.PostedFile.FileName.Trim()!=""
)
            {
                //上傳文件

                string extension = Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper();
                string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
DateTime.Now.Second.ToString();
                string path = Server.MapPath(".") + "/UploadFile/" + fileName +
extension;
                UploadFile.PostedFile.SaveAs(path);

                //加文字水印,注意,這裡的代碼和以下加圖片水印的代碼不能共存

                System.Drawing.Image image = System.Drawing.Image.FromFile(path);
                Graphics g =
Graphics.FromImage(image);
                g.DrawImage(image, 0, 0
, image.Width, image.Height);
                Font f = new Font("Verdana", 32
);
                Brush b = new
SolidBrush(Color.White);
                string addText =
AddText.Value.Trim();
                g.DrawString(addText, f, b, 10, 10
);
                g.Dispose();

                //加圖片水印

                System.Drawing.Image image = System.Drawing.Image.FromFile(path);
                System.Drawing.Image copyImage = System.Drawing.Image.FromFile( Server.MapPath(".") + "/Alex.gif"
);
                Graphics g =
Graphics.FromImage(image);
                g.DrawImage(copyImage, new Rectangle(image.Width-copyImage.Width, image.Height-

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved