Beispiel #1
0
        private static void SaveToFile(Bitmap bitmap, string imageFormat, string imagePath)
        {
            try
            {
                if (bitmap != null && !string.IsNullOrEmpty(imageFormat) && !string.IsNullOrEmpty(imagePath))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(imagePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(imagePath));
                    }

                    bitmap.Save(imagePath, ImageFormatCollection.GetByName(imageFormat).Format);
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #2
0
        private static void SaveToFile(Bitmap bitmap, string imageFormat, string imagePath)
        {
            try
            {
                if (bitmap != null && !string.IsNullOrEmpty(imageFormat) && !string.IsNullOrEmpty(imagePath))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(imagePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(imagePath));
                    }

                    Log.Write("Screenshot saved: " + imagePath);

                    bitmap.Save(imagePath, ImageFormatCollection.GetByName(imageFormat).Format);
                }
            }
            catch (Exception ex)
            {
                Log.Write("ScreenCapture::SaveToFile", ex);
            }
        }
Beispiel #3
0
        public static string ParseTags(string path, string imageFormat, string screenName, DateTime dateTimeScreenshotTaken)
        {
            if (!string.IsNullOrEmpty(imageFormat))
            {
                path = path.Replace("%format%", ImageFormatCollection.GetByName(imageFormat).Extension.TrimStart('.'));
            }

            if (!string.IsNullOrEmpty(screenName))
            {
                path = path.Replace("%screen%", screenName);
            }

            path = path.Replace("%year%", dateTimeScreenshotTaken.ToString("yyyy"));
            path = path.Replace("%month%", dateTimeScreenshotTaken.ToString("MM"));
            path = path.Replace("%day%", dateTimeScreenshotTaken.ToString("dd"));
            path = path.Replace("%hour%", dateTimeScreenshotTaken.ToString("HH"));
            path = path.Replace("%minute%", dateTimeScreenshotTaken.ToString("mm"));
            path = path.Replace("%second%", dateTimeScreenshotTaken.ToString("ss"));
            path = path.Replace("%millisecond%", dateTimeScreenshotTaken.ToString("fff"));

            return(path);
        }
Beispiel #4
0
        public static void TakeScreenshot()
        {
            try
            {
                int count = 0;

                string filename = m_folder + StringHelper.ParseTags("%CurrentDate%") + "\\%screen%\\" + StringHelper.ParseTags("%CurrentDate%_%CurrentTime%");

                foreach (Screen screen in Screen.AllScreens)
                {
                    Bitmap bitmap = GetScreenBitmap(screen, m_ratio);

                    count++;

                    if (count <= SCREEN_MAX)
                    {
                        SaveToFile(bitmap, m_format, filename.Replace("%screen%", count.ToString()) + ImageFormatCollection.GetByName(m_format).Extension);
                    }

                    System.GC.Collect();
                }

                SaveToFile(GetActiveWindowBitmap(), m_format, filename.Replace("%screen%", "5") + ImageFormatCollection.GetByName(m_format).Extension);

                m_count++;
            }
            catch (Exception)
            {
            }
        }