ArticleDirectory
- 1. Save the image in the clipboard to a file
- 2. Listen for events with clipboard changes
- 3. File similarity Identification
C # winform + windowsapi as a clipboard seamless Automatic Recorder (Video weapon)
The C # And window APIs are used to automatically save the pictures in the clipboard.VideoIs the best. Share.
Click the start button. When the clipboard content changes, the image is automatically saved to the specified position (saved as a jpg image) and the specified string is used as the file prefix, followed by the serial number. Therefore, this tool is closely used with the prtsc screenshot key. Press prtsc once to save an image. Even if you keep running the screenshot, You can execute each screenshot command.
In addition, the distinct button can check all the files in the path folder and automatically delete files with identical content. This is very practical.
Source code: http://files.cnblogs.com/bitzhuwei/bitzhuwei.Clipboard.Winform.zip
Release VersionProgramIn: http://files.cnblogs.com/bitzhuwei/bitzhuwei.Clipboard.Winform-release.zip
1. Save the image in the clipboard to a file
CodeAs follows.
1: VoidSavw.boardimage ()
2:{
3:VaR DATA = system. Windows. Forms. clipboard. getdataobject ();
4:VaR bmap = (image) (data. getdata (Typeof(System. Drawing. Bitmap )));
5:If(Bmap! =Null)
6:{
7:Bmap. Save ("Bitzhuwei.cnblogs.com.jpg", System. Drawing. imaging. imageformat. JPEG );
8:Bmap. Dispose ();
9:}
10:}
2. Listen for events with clipboard changes
Override the wndproc event of the main form, so that it can be implementedWhen and only whenThe clipboard is saved once when the content of the clipboard changes.
Windproc event where override falls into the main window Const Int Wm_drawclipboard = 0x308; Const Int Wm_changecbchain = 0x030d; Protected Override Void Wndproc ( Ref Message m ){ If (Nextclipboardviewer = Null ) Nextclipboardviewer = (intptr) setclipboardviewer (( Int ) This . Handle ); Switch (M. msg ){ Case Wm_changecbchain: If (M. wparam = nextclipboardviewer) {nextclipboardviewer = M. lparam ;} Else {Sendmessage (nextclipboardviewer, M. MSG, M. wparam, M. lparam );} Break ; Case Wm_drawclipboard: savw.boardimage (); // Pass the wm_drawclipboard message to the window in the next observation chain Sendmessage (nextclipboardviewer, M. MSG, M. wparam, M. lparam ); // Pass the wm_drawclipboard message to the window in the next observation chain Break ; Default : Base . Wndproc ( Ref M ); Break ;}}
3. File similarity Identification
You can use a single byte of the file stream to determine the size of the file. Most different files may not be able to tell how many times there will be different bytes, so I am confident in the efficiency of this method. I also tried to delete all the repeated files in two minutes for more than 1000 images (1280*800 full screen images) obtained from the video.
Deletes all redundant files with the same content in the specified folder. Private Void Deleteredundancyfiles ( String Directory) {var files = ( New Directoryinfo (directory). getfiles (" *. Jpg "); For ( Int I = 0; I <files. length; I ++ ){ For ( Int J = I + 1; j <files. length; j ++ ){ If (File. exists (files [I]. fullname) & file. exists (files [J]. fullname )){ Bool Removej = issamecontent (files, I, j );If (Removej ){ Try {File. Delete (files [J]. fullname );} Catch (Exception ){}}}}}} Private Static Bool Issamecontent (fileinfo [] files, Int I, Int J) {var result =True ; Using (Filestream FSI = New Filestream (files [I]. fullname, filemode. Open )){ Using (Filestream FSJ = New Filestream (files [J]. fullname, filemode. Open) {var counti = 0; var countj = 0; Do { Const Int Length = 100; var bytesi = New Byte [Length]; var bytesj = New Byte [Length]; counti = FSI. Read (bytesi, 0, length); countj = FSJ. Read (bytesj, 0, length ); If (Counti! = Countj) {result = False ;} Else { For ( Int K = 0; k <counti; k ++ ){ If (Bytesi [k]! = Bytesj [k]) {result = False ; Break ;}}}} While (Result & counti> 0 & countj> 0 );}} Return Result ;}