C#監(jiān)控文件夾并自動(dòng)給圖片文件打水印的方法
本文實(shí)例講述了C#監(jiān)控文件夾并自動(dòng)給圖片文件打水印的方法。分享給大家供大家參考。具體分析如下:
個(gè)人私心的緣故,經(jīng)常寫(xiě)一些博客之類(lèi)的文章,由于看到網(wǎng)絡(luò)上面好多同志轉(zhuǎn)載后不標(biāo)明出處,所以特地寫(xiě)了這么一個(gè)小程序,這個(gè)小程序的功能是當(dāng)我在頁(yè)面上通過(guò)QQ截圖之后,把截到的圖片保存到一個(gè)指定的路徑,然后工具自動(dòng)幫我把圖片上面加上水印。
下面是全部代碼:
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); } } }
來(lái)看一下效果
這里的代碼非常簡(jiǎn)單,大家不要噴我
我是一只辛勤耕耘的螞蟻
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- 深入分析WPF客戶(hù)端讀取高清圖片卡以及縮略圖的解決方法詳解
- WPF TextBox和PasswordBox添加水印
- WPF 自定義雷達(dá)圖開(kāi)發(fā)實(shí)例教程
- 在WinForm和WPF中使用GMap.Net地圖插件簡(jiǎn)單教程
- C#(.net)水印圖片的生成完整實(shí)例
- C# 添加圖片水印類(lèi)實(shí)現(xiàn)代碼
- .net c# gif動(dòng)畫(huà)如何添加圖片水印實(shí)現(xiàn)思路及代碼
- C#給圖片添加水印完整實(shí)例
- C#給圖片加水印的簡(jiǎn)單實(shí)現(xiàn)方法
- c#圖片添加水印的實(shí)例代碼
- WPF實(shí)現(xiàn)圖片合成或加水印的方法【2種方法】
相關(guān)文章
C#實(shí)現(xiàn)下載網(wǎng)頁(yè)HTML源碼的方法
這篇文章主要介紹了C#實(shí)現(xiàn)下載網(wǎng)頁(yè)HTML源碼的方法,是一個(gè)非常實(shí)用的技巧,還包含了對(duì)于下載失敗的判斷等邏輯處理,需要的朋友可以參考下2014-09-09Unity游戲開(kāi)發(fā)中的設(shè)計(jì)模式之策略模式
策略模式是Unity游戲開(kāi)發(fā)中常用的設(shè)計(jì)模式之一,用于封裝一系列算法或行為,并使這些算法或行為可以相互替換。通過(guò)策略模式,可以在運(yùn)行時(shí)動(dòng)態(tài)地選擇算法或行為,實(shí)現(xiàn)游戲中的多樣性和可擴(kuò)展性。常見(jiàn)的應(yīng)用包括AI行為、武器攻擊、移動(dòng)方式等2023-05-05C#刪除只讀文件或文件夾(解決File.Delete無(wú)法刪除文件)
這篇文章主要介紹了C#刪除只讀文件或文件夾(解決File.Delete無(wú)法刪除文件),需要的朋友可以參考下2015-09-09C#實(shí)現(xiàn)讓窗體永遠(yuǎn)在窗體最前面顯示的實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)讓窗體永遠(yuǎn)在窗體最前面顯示,功能非常實(shí)用,需要的朋友可以參考下2014-07-07C# [ImportDll()] 知識(shí)小結(jié)
今天小編就為大家分享一篇關(guān)于C# [ImportDll()] 知識(shí)小結(jié),小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-01-01C#實(shí)現(xiàn)CSV文件讀寫(xiě)的示例詳解
這篇文章主要介紹了CsvHelper、TextFieldParser、正則表達(dá)式三種解析CSV文件的方法,順帶也會(huì)介紹一下CSV文件的寫(xiě)方法,需要的可以參考一下2023-05-05C#和JavaScript實(shí)現(xiàn)交互的方法
最近做一個(gè)小項(xiàng)目不可避免的需要前端腳本與后臺(tái)進(jìn)行交互。由于是在asp.net中實(shí)現(xiàn),故問(wèn)題演化成asp.net中jiavascript與后臺(tái)c#如何進(jìn)行交互。2015-05-05