@@ -7,8 +7,7 @@ namespace ExceptionReporting.Core
77{
88 internal interface IScreenshotTaker
99 {
10- Bitmap TakeScreenShot ( ) ;
11- string GetImageAsFile ( Bitmap bitmap ) ;
10+ string TakeScreenShot ( ) ;
1211 }
1312
1413 /// <summary>
@@ -19,8 +18,8 @@ internal class ScreenshotTaker : IScreenshotTaker
1918 private const string ScreenshotFileName = "exceptionreport-screenshot.jpg" ;
2019
2120 /// <summary> Take a screenshot (supports multiple monitors) </summary>
22- /// <returns>Bitmap of the screen, as at the time called </returns>
23- public Bitmap TakeScreenShot ( )
21+ /// <returns>temp file name of JPEG image </returns>
22+ public string TakeScreenShot ( )
2423 {
2524 if ( ExceptionReporter . IsRunningMono ( ) ) return null ;
2625
@@ -31,24 +30,25 @@ public Bitmap TakeScreenShot()
3130 rectangle = Rectangle . Union ( rectangle , screen . Bounds ) ;
3231 }
3332
34- var bitmap = new Bitmap ( rectangle . Width , rectangle . Height , PixelFormat . Format32bppArgb ) ;
35-
36- using ( var graphics = Graphics . FromImage ( bitmap ) )
33+ using ( var bitmap = new Bitmap ( rectangle . Width , rectangle . Height , PixelFormat . Format32bppArgb ) )
3734 {
38- graphics . CopyFromScreen ( rectangle . X , rectangle . Y , 0 , 0 , rectangle . Size , CopyPixelOperation . SourceCopy ) ;
39- }
4035
41- return bitmap ;
36+ using ( var graphics = Graphics . FromImage ( bitmap ) )
37+ {
38+ graphics . CopyFromScreen ( rectangle . X , rectangle . Y , 0 , 0 , rectangle . Size , CopyPixelOperation . SourceCopy ) ;
39+ }
40+
41+ return GetImageAsFile ( bitmap ) ;
42+ }
4243 }
4344
4445 /// <summary>
4546 /// Return the supplied Bitmap, as a file on the system, in JPEG format
4647 /// </summary>
4748 /// <param name="bitmap">The Bitmap to save</param>
48- /// <returns></returns>
49- public string GetImageAsFile ( Bitmap bitmap )
49+ private static string GetImageAsFile ( Image bitmap )
5050 {
51- var tempFileName = Path . GetTempPath ( ) + ScreenshotFileName ; // the image is not deleted but the same file is reused every time
51+ var tempFileName = Path . GetTempPath ( ) + ScreenshotFileName ; // image is not deleted but same file is reused
5252 bitmap . Save ( tempFileName , ImageFormat . Jpeg ) ;
5353 return tempFileName ;
5454 }
0 commit comments