国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#監控文件夾并自動給圖片文件打水印的方法

2020-01-24 01:50:06
字體:
來源:轉載
供稿:網友

本文實例講述了C#監控文件夾并自動給圖片文件打水印的方法。分享給大家供大家參考。具體分析如下:

個人私心的緣故,經常寫一些博客之類的文章,由于看到網絡上面好多同志轉載后不標明出處,所以特地寫了這么一個小程序,這個小程序的功能是當我在頁面上通過QQ截圖之后,把截到的圖片保存到一個指定的路徑,然后工具自動幫我把圖片上面加上水印。

下面是全部代碼:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace FolderWatcher{  public partial class Form1 : Form  {    public Form1()    {      InitializeComponent();    }    private static string text = "http://www.cnblogs.com/zhuzhenyu";    private static string path = @"E:/FolderWatcher";    private void button1_Click(object sender, EventArgs e)    {      if (!string.IsNullOrEmpty(this.textBox1.Text))      {        path = this.textBox1.Text;      }      if (!string.IsNullOrEmpty(this.textBox2.Text))      {        text = this.textBox2.Text;      }      WatcherStrat(path, "*.*");    }    private static void WatcherStrat(string path, string filter)    {      FileSystemWatcher watcher = new FileSystemWatcher();      watcher.Path = path;      watcher.Filter = filter;      watcher.Created += new FileSystemEventHandler(OnProcess);      watcher.EnableRaisingEvents = true;      watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess                  | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;      watcher.IncludeSubdirectories = true;    }    private static void OnProcess(object source, FileSystemEventArgs e)    {      if (e.ChangeType == WatcherChangeTypes.Created)      {        OnCreated(source, e);      }    }    private static void OnCreated(object source, FileSystemEventArgs e)    {      if (e.FullPath.IndexOf("_new.") < 0)      {        FinePic(e.FullPath, text, e.FullPath.Replace(".", "_new."), new Font("宋體", 15, FontStyle.Bold));      }    }    /// <summary>    /// 圖片水印    /// </summary>    /// <param name="FileName">源文件路徑</param>    /// <param name="wText">水印文字</param>    /// <param name="savePath">保存路徑</param>    /// <param name="font">字體樣式</param>    public static void FinePic(string FileName, string wText, string savePath, Font font)    {      Bitmap bmp = new Bitmap(FileName);      System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);      g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;      g.DrawString(wText, font, new SolidBrush(Color.FromArgb(70, Color.Red)), 60, bmp.Height - 120);//加水印      bmp.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);    }  }}

來看一下效果

這里的代碼非常簡單,大家不要噴我

我是一只辛勤耕耘的螞蟻

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 滁州市| 商都县| 大庆市| 溆浦县| 乌拉特前旗| 青龙| 磴口县| 临潭县| 天峻县| 枣阳市| 牟定县| 垫江县| 文水县| 汉中市| 宣化县| 涿鹿县| 五河县| 登封市| 鄂托克前旗| 林州市| 武强县| 黔西| 南安市| 邓州市| 兴宁市| 中阳县| 河北省| 堆龙德庆县| 娱乐| 六枝特区| 抚顺县| 东平县| 宁阳县| 丰都县| 新宾| 昭通市| 洛川县| 云安县| 会东县| 读书| 宁化县|