예제 #1
0
        public static Image Snip(ScreenshotType type)
        {
            switch(type)
            {
                case ScreenshotType.FULL:
                    return CreateScreenshot(0, 0, SystemInformation.VirtualScreen.Width,SystemInformation.VirtualScreen.Height);

                case ScreenshotType.DEFINED:
                     SnippingTool snipper = new SnippingTool(CreateScreenshot(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height), new Point(SystemInformation.VirtualScreen.Left, SystemInformation.VirtualScreen.Top));
                     if (snipper.ShowDialog() == DialogResult.OK)
                     {
                         return snipper.Image;
                     }
                     break;
                case ScreenshotType.ACTIVE:
                    RECT windowRectangle;
                    GetWindowRect((System.IntPtr)GetForegroundWindow(), out windowRectangle);
                    return CreateScreenshot(windowRectangle.Left, windowRectangle.Top, windowRectangle.Right - windowRectangle.Left, windowRectangle.Bottom - windowRectangle.Top);
            }
            return null;
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="format"></param>
        /// <param name="component"></param>
        /// <param name="screenshotType"></param>
        /// <param name="jpegQuality"></param>
        /// <param name="viewId"></param>
        /// <param name="bitmap"></param>
        /// <param name="label"></param>
        /// <param name="windowTitle"></param>
        /// <param name="processName"></param>
        /// <param name="screenshotCollection"></param>
        /// <returns></returns>
        public bool TakeScreenshot(string path, ImageFormat format, int component, ScreenshotType screenshotType, int jpegQuality,
                                   Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName, ScreenshotCollection screenshotCollection)
        {
            try
            {
                if (!string.IsNullOrEmpty(path) && path.Length < MAX_WINDOWS_PATH_LENGTH)
                {
                    if (Log.DebugMode)
                    {
                        Log.Write("Attempting to write image to file at path \"" + path + "\"");
                    }

                    FileInfo fileInfo = new FileInfo(path);

                    if (fileInfo.Directory != null && fileInfo.Directory.Root.Exists)
                    {
                        // This is a normal path used in Windows (such as "C:\screenshots\").
                        if (!path.StartsWith(FileSystem.PathDelimiter))
                        {
                            DriveInfo driveInfo = new DriveInfo(fileInfo.Directory.Root.FullName);

                            if (driveInfo.IsReady)
                            {
                                double freeDiskSpacePercentage = (driveInfo.AvailableFreeSpace / (float)driveInfo.TotalSize) * 100;

                                if (Log.DebugMode)
                                {
                                    Log.Write("Percentage of free disk space on drive " + fileInfo.Directory.Root.FullName + " is " + (int)freeDiskSpacePercentage + "%");
                                }

                                if (freeDiskSpacePercentage > MIN_FREE_DISK_SPACE_PERCENTAGE)
                                {
                                    string dirName = Path.GetDirectoryName(path);

                                    if (!string.IsNullOrEmpty(dirName))
                                    {
                                        if (!Directory.Exists(dirName))
                                        {
                                            Directory.CreateDirectory(dirName);

                                            Log.Write("Directory \"" + dirName + "\" did not exist so it was created");
                                        }

                                        screenshotCollection.Add(new Screenshot(DateTimePreviousCycle, path, format, component, screenshotType, windowTitle, processName, viewId, label));

                                        SaveToFile(path, format, jpegQuality, bitmap);
                                    }
                                }
                                else
                                {
                                    Log.Write($"ERROR: Unable to save screenshot due to lack of available disk space on drive {fileInfo.Directory.Root.FullName} so screen capture session is being stopped");
                                    return(false);
                                }
                            }
                            else
                            {
                                Log.Write("WARNING: Unable to save screenshot. Drive not ready");
                            }
                        }
                        else
                        {
                            // This is UNC network share path (such as "\\SERVER\screenshots\").
                            string dirName = Path.GetDirectoryName(path);

                            if (!string.IsNullOrEmpty(dirName))
                            {
                                if (!Directory.Exists(dirName))
                                {
                                    Directory.CreateDirectory(dirName);

                                    Log.Write("Directory \"" + dirName + "\" did not exist so it was created");
                                }

                                screenshotCollection.Add(new Screenshot(DateTimePreviousCycle, path, format, component, screenshotType, windowTitle, processName, viewId, label));

                                SaveToFile(path, format, jpegQuality, bitmap);
                            }
                        }
                    }
                    else
                    {
                        Log.Write("WARNING: Unable to save screenshot. Directory root does not exist");
                    }
                }
                else
                {
                    Log.Write($"No path available or path length exceeds {MAX_WINDOWS_PATH_LENGTH} characters");

                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Write("ScreenCapture::TakeScreenshot", ex);

                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Saves the captured bitmap image as a screenshot to an image file.
        /// </summary>
        /// <param name="path">The filepath of the image file to write to.</param>
        /// <param name="format">The format of the image file.</param>
        /// <param name="component">The component of the screenshot to be saved. This could be the active window or a screen.</param>
        /// <param name="screenshotType">The type of screenshot to save. This could be the active window, a region, or a screen.</param>
        /// <param name="jpegQuality">The JPEG quality setting for JPEG images being saved.</param>
        /// <param name="viewId">The unique identifier to identify a particular region or screen.</param>
        /// <param name="bitmap">The bitmap image to write to the image file.</param>
        /// <param name="label">The current label being used at the time of capture which we will apply to the screenshot object.</param>
        /// <param name="windowTitle">The title of the window being captured.</param>
        /// <param name="processName">The process name of the application being captured.</param>
        /// <param name="screenshotCollection">A collection of screenshot objects.</param>
        /// <returns>A boolean to determine if we successfully saved the screenshot.</returns>
        public bool SaveScreenshot(string path, ImageFormat format, int component, ScreenshotType screenshotType, int jpegQuality,
                                   Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName, ScreenshotCollection screenshotCollection)
        {
            try
            {
                if (!string.IsNullOrEmpty(path) && path.Length >= MAX_WINDOWS_PATH_LENGTH)
                {
                    // We just want to log a normal message and not stop the screen capture session because we want to continue
                    // for other components that are using paths which are still valid.
                    Log.WriteMessage($"No path available at \"{path}\" or path length exceeds {MAX_WINDOWS_PATH_LENGTH} characters");
                }

                if (!string.IsNullOrEmpty(path) && path.Length < MAX_WINDOWS_PATH_LENGTH)
                {
                    Log.WriteDebugMessage("Attempting to write image to file at path \"" + path + "\"");

                    // This is a normal path used in Windows (such as "C:\screenshots\").
                    if (!path.StartsWith(FileSystem.PathDelimiter))
                    {
                        if (FileSystem.DriveReady(path))
                        {
                            int    lowDiskSpacePercentageThreshold = Convert.ToInt32(Settings.Application.GetByKey("LowDiskPercentageThreshold", defaultValue: 1).Value);
                            double freeDiskSpacePercentage         = FileSystem.FreeDiskSpacePercentage(path);

                            Log.WriteDebugMessage("Percentage of free disk space on drive for \"" + path + "\" is " + (int)freeDiskSpacePercentage + "% and low disk percentage threshold is set to " + lowDiskSpacePercentageThreshold + "%");

                            if (freeDiskSpacePercentage > lowDiskSpacePercentageThreshold)
                            {
                                string dirName = FileSystem.GetDirectoryName(path);

                                if (!string.IsNullOrEmpty(dirName))
                                {
                                    if (!FileSystem.DirectoryExists(dirName))
                                    {
                                        FileSystem.CreateDirectory(dirName);

                                        Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created");
                                    }

                                    Screenshot screenshot = new Screenshot(DateTimeScreenshotsTaken, path, format, component, screenshotType, windowTitle, processName, viewId, label);

                                    screenshotCollection.Add(screenshot);

                                    SaveToFile(path, format, jpegQuality, bitmap);
                                }
                            }
                            else
                            {
                                // There is not enough disk space on the drive so stop the current running screen capture session and log an error message.
                                Log.WriteErrorMessage($"Unable to save screenshot due to lack of available disk space on drive for {path} (at " + freeDiskSpacePercentage + "%) which is lower than the LowDiskPercentageThreshold setting that is currently set to " + lowDiskSpacePercentageThreshold + "% so screen capture session is being stopped");

                                return(false);
                            }
                        }
                        else
                        {
                            // Drive isn't ready so log an error message.
                            Log.WriteErrorMessage($"Unable to save screenshot for \"{path}\" because the drive is not found or not ready");
                        }
                    }
                    else
                    {
                        // This is UNC network share path (such as "\\SERVER\screenshots\").
                        string dirName = FileSystem.GetDirectoryName(path);

                        if (!string.IsNullOrEmpty(dirName))
                        {
                            try
                            {
                                if (!FileSystem.DirectoryExists(dirName))
                                {
                                    FileSystem.CreateDirectory(dirName);

                                    Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created");
                                }

                                screenshotCollection.Add(new Screenshot(DateTimeScreenshotsTaken, path, format, component, screenshotType, windowTitle, processName, viewId, label));

                                SaveToFile(path, format, jpegQuality, bitmap);
                            }
                            catch (Exception)
                            {
                                // We don't want to stop the screen capture session at this point because there may be other components that
                                // can write to their given paths. If this is a misconfigured path for a particular component then just log an error.
                                Log.WriteErrorMessage($"Cannot write to \"{path}\" because the user may not have the appropriate permissions to access the path");
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("ScreenCapture::SaveScreenshot", ex);

                return(false);
            }
        }
예제 #4
0
        private void ScreenshotInternal(Texture source, int maximumWidth, int maximumHeight, ScreenshotType type, Action <byte[], object> callback, object state)
        {
            ScreenshotOperation operation = this.GetOperation();

            operation.Identifier    = ScreenshotRecorder.nextIdentifier++;
            operation.Source        = source;
            operation.MaximumWidth  = maximumWidth;
            operation.MaximumHeight = maximumHeight;
            operation.Type          = type;
            operation.Callback      = callback;
            operation.State         = state;
            AsyncGPUReadback.Request(source, 0, TextureFormat.RGBA32, operation.ScreenshotCallbackDelegate);
        }
예제 #5
0
 public void Screenshot(Texture2D source, int maximumWidth, int maximumHeight, ScreenshotType type, Action <byte[], object> callback, object state)
 {
     this.ScreenshotInternal(source, maximumWidth, maximumHeight, type, callback, state);
 }
예제 #6
0
        public void Screenshot(int maximumWidth, int maximumHeight, ScreenshotType type, Action <byte[], object> callback, object state)
        {
            Texture2D texture = ScreenCapture.CaptureScreenshotAsTexture();

            this.Screenshot(texture, maximumWidth, maximumHeight, type, callback, state);
        }
예제 #7
0
        public Screenshot(DateTime dateTime, string path, ImageFormat format, int component, ScreenshotType screenshotType, string windowTitle, Guid viewId, string label)
        {
            ViewId         = viewId;
            Date           = dateTime.ToString(MacroParser.DateFormat);
            Time           = dateTime.ToString(MacroParser.TimeFormat);
            Path           = path;
            Format         = format;
            Component      = component;
            ScreenshotType = screenshotType;
            WindowTitle    = windowTitle;
            Label          = label;

            Slide = new Slide()
            {
                Name  = "{date=" + Date + "}{time=" + Time + "}",
                Date  = Date,
                Value = Time + (!string.IsNullOrEmpty(windowTitle) ? " [" + windowTitle + "]" : string.Empty)
            };
        }
예제 #8
0
        public bool TakeScreenshot(string path, ImageFormat format, int component, ScreenshotType screenshotType,
                                   int jpegQuality, Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName,
                                   ScreenCollection screenCollection, RegionCollection regionCollection, ScreenshotCollection screenshotCollection)
        {
            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    Log.Write("Attempting to write image to file at path \"" + path + "\"");

                    FileInfo fileInfo = new FileInfo(path);

                    if (fileInfo.Directory != null && fileInfo.Directory.Root.Exists)
                    {
                        DriveInfo driveInfo = new DriveInfo(fileInfo.Directory.Root.FullName);

                        if (driveInfo.IsReady)
                        {
                            double freeDiskSpacePercentage = (driveInfo.AvailableFreeSpace / (float)driveInfo.TotalSize) * 100;

                            Log.Write("Percentage of free disk space on drive " + fileInfo.Directory.Root.FullName + " is " + (int)freeDiskSpacePercentage + "%");

                            if (freeDiskSpacePercentage > MIN_FREE_DISK_SPACE_PERCENTAGE)
                            {
                                string dirName = Path.GetDirectoryName(path);

                                if (!string.IsNullOrEmpty(dirName))
                                {
                                    if (!Directory.Exists(dirName))
                                    {
                                        Directory.CreateDirectory(dirName);

                                        Log.Write("Directory \"" + dirName + "\" did not exist so it was created");
                                    }

                                    screenshotCollection.Add(new Screenshot(DateTimePreviousCycle, path, format, component, screenshotType, windowTitle, processName, viewId, label));

                                    SaveToFile(path, format, jpegQuality, bitmap);
                                }
                            }
                            else
                            {
                                Log.Write($"ERROR: Unable to save screenshot due to lack of available disk space on drive {fileInfo.Directory.Root.FullName} so screen capture session is being stopped");
                                return(false);
                            }
                        }
                        else
                        {
                            Log.Write("WARNING: Unable to save screenshot. Drive not ready");
                        }
                    }
                    else
                    {
                        Log.Write("WARNING: Unable to save screenshot. Directory root does not exist");
                    }
                }
                else
                {
                    Log.Write("No path available");
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Write("ScreenCapture::TakeScreenshot", ex);
                return(false);
            }
        }
예제 #9
0
        public ActionResult GetScreenshot(long testId, ScreenshotType screenshotType)
        {
            var image = this.testResultService.GetScreenshot(testId, screenshotType);

            return(ActionResultFactory.ImageResult(image));
        }
예제 #10
0
        private static Bitmap GetWindowScreenshot(Form form, Rectangle rectangle, ScreenshotType screenshotType)
        {
            Bitmap windowScreenshot = GetWindowScreenshot(form, screenshotType);

            return(windowScreenshot.Clone(rectangle, windowScreenshot.PixelFormat));
        }
예제 #11
0
 public static void CopyToClipboard(Form form, ScreenshotType screenshotType)
 {
     Clipboard.SetImage(GetWindowScreenshot(form, screenshotType));
 }
예제 #12
0
 public static void SaveInFile(Form form, string fileName, ScreenshotType screenshotType)
 {
     Save(GetWindowScreenshot(form, screenshotType), fileName);
 }
예제 #13
0
        /// <summary>
        /// The constructor for creating a screenshot.
        /// </summary>
        /// <param name="dateTime">The date/time the screenshot was taken.</param>
        /// <param name="path">The path of the filename for the screenshot.</param>
        /// <param name="format">The image format of the screenshot.</param>
        /// <param name="component">The component used for the screenshot.</param>
        /// <param name="screenshotType">The type of screenshot.</param>
        /// <param name="windowTitle">The title of the active window when the screenshot was taken.</param>
        /// <param name="processName">The process name of the active application when the screenshot was taken.</param>
        /// <param name="viewId">The view ID associated with either the screen or the region for the screenshot.</param>
        /// <param name="label">The label to be applied to the screenshot.</param>
        public Screenshot(DateTime dateTime, string path, ImageFormat format, int component, ScreenshotType screenshotType, string windowTitle, string processName, Guid viewId, string label)
        {
            if (string.IsNullOrEmpty(windowTitle))
            {
                return;
            }

            ViewId         = viewId;
            Date           = dateTime.ToString(MacroParser.DateFormat);
            Time           = dateTime.ToString(MacroParser.TimeFormat);
            Path           = path;
            Format         = format;
            Component      = component;
            ScreenshotType = screenshotType;
            WindowTitle    = windowTitle;
            ProcessName    = processName + ".exe";
            Label          = label;
            Saved          = false;
            Version        = Settings.ApplicationVersion;

            Slide = new Slide()
            {
                Name  = "{date=" + Date + "}{time=" + Time + "}",
                Date  = Date,
                Value = Time + " [" + windowTitle + "]"
            };
        }
예제 #14
0
        public static void TakeScreenshot(Screen screen, DateTime dateTimeScreenshotTaken, string format, string screenName, string path, int screenNumber, ScreenshotType screenshotType, long jpegQualityLevel, bool mouse)
        {
            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    Bitmap bitmap = screenNumber == 5 ? GetActiveWindowBitmap() : GetScreenBitmap(screen, Ratio, format, mouse);

                    if (bitmap != null)
                    {
                        Screenshot screenshot = new Screenshot(dateTimeScreenshotTaken, path, screenNumber, format, screenshotType == ScreenshotType.User ? ScreenshotCollection.Count : -1);

                        SaveToFile(bitmap, jpegQualityLevel, format, screenshot.Path, screenshotType);

                        ScreenshotCollection.Add(screenshot, screenshotType);

                        GC.Collect();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("ScreenCapture::TakeScreenshot", ex);
            }
        }
예제 #15
0
 public void Screenshot(ScreenshotType type, Action <Image <Rgb24> > callback)
 {
     callback(new Image <Rgb24>(ScreenSize.X, ScreenSize.Y));
 }
예제 #16
0
        private async void TakeScreenshot(ScreenshotType screenshotType)
        {
            if (screenshotPending)
                return;

            layoutPb.Visibility = ViewStates.Visible;
            iView.Visibility = ViewStates.Gone;
            screenshotAll.SetEnabled(false);
            screenshotOSD.SetEnabled(false);
            screenshotPicture.SetEnabled(false);
            saveMenu.SetEnabled(false);

            screenshotPending = true;
            var response = await ConnectionManager.GetScreenShotOfCurrentService(screenshotType);

            layoutPb.Visibility = ViewStates.Gone;
            iView.Visibility = ViewStates.Visible; 
            screenshotAll.SetEnabled(true);
            screenshotOSD.SetEnabled(true);
            screenshotPicture.SetEnabled(true);
            saveMenu.SetEnabled(true);

            if (response == null)
            {
                screenshotPending = false;
                iView.SetScaleType(ImageView.ScaleType.Center);
                iView.SetImageDrawable(defaultImage);
                return;
            }

            iView.SetScaleType(ImageView.ScaleType.FitCenter);
            iView.SetImageBitmap(CreateBitmapFromBytes(response.Screenshot));
            screenshotPending = false;
        }
예제 #17
0
 public string GetAppScreenshotFilePath(Guid appGuid, ScreenshotType screenshotType, ScreenshotSize screenshotSize, int screenshotIndex)
 {
     return(AppBiz.GetAppScreenshotFilePath(appGuid, screenshotType, screenshotSize, screenshotIndex));
 }