11using System ;
2+ using System . Drawing ;
23using System . Drawing . Imaging ;
34using System . IO ;
45using System . Windows ;
@@ -7,64 +8,70 @@ namespace Ink_Canvas
78{
89 public partial class MainWindow : Window
910 {
10- private void SaveScreenShot ( bool isHideNotification , string fileName = null )
11+ private void SaveScreenshot ( bool isHideNotification , string fileName = null )
1112 {
12- /*
13- var size = System.Windows.Forms.SystemInformation.PrimaryMonitorSize;
14- var rc = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(size.Width, size.Height));
15- */
16- System . Drawing . Rectangle rc = System . Windows . Forms . SystemInformation . VirtualScreen ;
17-
18- var bitmap = new System . Drawing . Bitmap ( rc . Width , rc . Height , System . Drawing . Imaging . PixelFormat . Format32bppArgb ) ;
19-
20- using ( System . Drawing . Graphics memoryGrahics = System . Drawing . Graphics . FromImage ( bitmap ) )
13+ var bitmap = GetScreenshotBitmap ( ) ;
14+ string savePath = Settings . Automation . AutoSavedStrokesLocation + @"\Auto Saved - Screenshots" ;
15+ if ( fileName == null ) fileName = DateTime . Now . ToString ( "u" ) . Replace ( ":" , "-" ) ;
16+ if ( Settings . Automation . IsSaveScreenshotsInDateFolders )
2117 {
22- memoryGrahics . CopyFromScreen ( rc . X , rc . Y , 0 , 0 , rc . Size , System . Drawing . CopyPixelOperation . SourceCopy ) ;
18+ savePath += @"\" + DateTime . Now . ToString ( "yyyy-MM-dd" ) ;
2319 }
24-
25- if ( Settings . Automation . IsSaveScreenshotsInDateFolders )
20+ savePath += @"\" + fileName + ".png" ;
21+ if ( ! Directory . Exists ( Path . GetDirectoryName ( savePath ) ) )
2622 {
27- if ( string . IsNullOrWhiteSpace ( fileName ) ) fileName = DateTime . Now . ToString ( "HH-mm-ss" ) ;
28- string savePath = Settings . Automation . AutoSavedStrokesLocation + @"\Auto Saved - Screenshots\{DateTime.Now.Date:yyyyMMdd}\{fileName}.png" ;
29- if ( ! Directory . Exists ( Path . GetDirectoryName ( savePath ) ) )
30- {
31- Directory . CreateDirectory ( Path . GetDirectoryName ( savePath ) ) ;
32- }
33- bitmap . Save ( savePath , ImageFormat . Png ) ;
34- if ( ! isHideNotification )
35- {
36- ShowNotification ( "截图成功保存至 " + savePath ) ;
37- }
23+ Directory . CreateDirectory ( Path . GetDirectoryName ( savePath ) ) ;
3824 }
39- else
25+ bitmap . Save ( savePath , ImageFormat . Png ) ;
26+ if ( Settings . Automation . IsAutoSaveStrokesAtScreenshot )
4027 {
41- string savePath = Settings . Automation . AutoSavedStrokesLocation + @"\Auto Saved - Screenshots" ;
42- if ( ! Directory . Exists ( savePath ) )
43- {
44- Directory . CreateDirectory ( savePath ) ;
45- }
46- bitmap . Save ( savePath + @"\" + DateTime . Now . ToString ( "u" ) . Replace ( ':' , '-' ) + ".png" , ImageFormat . Png ) ;
47- if ( ! isHideNotification )
48- {
49- ShowNotification ( "截图成功保存至 " + savePath + @"\" + DateTime . Now . ToString ( "u" ) . Replace ( ':' , '-' ) + ".png" ) ;
50- }
28+ SaveInkCanvasStrokes ( false , false ) ;
29+ }
30+ if ( ! isHideNotification )
31+ {
32+ ShowNotification ( "截图成功保存至 " + savePath ) ;
5133 }
52- if ( Settings . Automation . IsAutoSaveStrokesAtScreenshot ) SaveInkCanvasStrokes ( false , false ) ;
5334 }
5435
5536 private void SaveScreenShotToDesktop ( )
5637 {
57- System . Drawing . Rectangle rc = System . Windows . Forms . SystemInformation . VirtualScreen ;
58- var bitmap = new System . Drawing . Bitmap ( rc . Width , rc . Height , System . Drawing . Imaging . PixelFormat . Format32bppArgb ) ;
59-
60- using ( System . Drawing . Graphics memoryGrahics = System . Drawing . Graphics . FromImage ( bitmap ) )
61- {
62- memoryGrahics . CopyFromScreen ( rc . X , rc . Y , 0 , 0 , rc . Size , System . Drawing . CopyPixelOperation . SourceCopy ) ;
63- }
38+ var bitmap = GetScreenshotBitmap ( ) ;
6439 string savePath = Environment . GetFolderPath ( Environment . SpecialFolder . DesktopDirectory ) ;
6540 bitmap . Save ( savePath + @"\" + DateTime . Now . ToString ( "u" ) . Replace ( ':' , '-' ) + ".png" , ImageFormat . Png ) ;
6641 ShowNotification ( "截图成功保存至【桌面" + @"\" + DateTime . Now . ToString ( "u" ) . Replace ( ':' , '-' ) + ".png】" ) ;
6742 if ( Settings . Automation . IsAutoSaveStrokesAtScreenshot ) SaveInkCanvasStrokes ( false , false ) ;
6843 }
44+
45+ private void SavePPTScreenshot ( string fileName )
46+ {
47+ var bitmap = GetScreenshotBitmap ( ) ;
48+ string savePath = Settings . Automation . AutoSavedStrokesLocation + @"\Auto Saved - PPT Screenshots" ;
49+ if ( Settings . Automation . IsSaveScreenshotsInDateFolders )
50+ {
51+ savePath += @"\" + DateTime . Now . ToString ( "yyyy-MM-dd" ) ;
52+ }
53+ if ( fileName == null ) fileName = DateTime . Now . ToString ( "u" ) . Replace ( ":" , "-" ) ;
54+ savePath += @"\" + fileName + ".png" ;
55+ if ( ! Directory . Exists ( Path . GetDirectoryName ( savePath ) ) )
56+ {
57+ Directory . CreateDirectory ( Path . GetDirectoryName ( savePath ) ) ;
58+ }
59+ bitmap . Save ( savePath , ImageFormat . Png ) ;
60+ if ( Settings . Automation . IsAutoSaveStrokesAtScreenshot )
61+ {
62+ SaveInkCanvasStrokes ( false , false ) ;
63+ }
64+ }
65+
66+ private Bitmap GetScreenshotBitmap ( )
67+ {
68+ Rectangle rc = System . Windows . Forms . SystemInformation . VirtualScreen ;
69+ var bitmap = new Bitmap ( rc . Width , rc . Height , PixelFormat . Format32bppArgb ) ;
70+ using ( Graphics memoryGrahics = Graphics . FromImage ( bitmap ) )
71+ {
72+ memoryGrahics . CopyFromScreen ( rc . X , rc . Y , 0 , 0 , rc . Size , CopyPixelOperation . SourceCopy ) ;
73+ }
74+ return bitmap ;
75+ }
6976 }
7077}
0 commit comments