Because of my private interest, I often write some blogs and so on.ArticleBecause many comrades on the Internet do not indicate the source after reprinting, so I wrote such a smallProgramThe function of this applet is to save the captured image to a specified path after I use QQ on the page, and then the tool automatically adds a watermark to the image.
Write thisCodeFor more information, see http://www.cnblogs.com/springyangwc/archive/2011/08/27/2155547.html.
Below is all the code
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 Button#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. policyfilter = Policyfilters. Attributes | policyfilters. creationtime | policyfilters. directoryname | policyfilters. filename | Policyfilters. lastaccess | Policyfilters. lastwrite | policyfilters. 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> /// Image Watermark /// </Summary> /// <Param name = "FILENAME"> Source File Path </Param> /// <Param name = "wtext"> Watermark text </Param> /// <Param name = "savepath"> Save path </Param> /// <Param name = "font"> Font Style </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 ); // Add watermarks BMP. Save (savepath, system. Drawing. imaging. imageformat. JPEG );}}}
Let's take a look at the effect.
The code here is very simple.