Monitor the file modification Applet in the folder

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.