示例#1
0
 /// <summary>
 /// Capture the screen and save it into a file, which portion of the screen is captured
 /// is defined by <paramref name="typeOfCapture"/>.
 /// </summary>
 /// <param name="typeOfCapture">Selects, what is actually captured, see <see cref="CaptureType"/>.</param>
 /// <param name="filename">The name of the target file. The extension in there is ignored,
 /// it will replaced by an extension derived from the desired file format.</param>
 /// <param name="format">The format of the file.</param>
 /// <returns>An array of images captured.</returns>
 public virtual Bitmap[] Capture(CaptureType typeOfCapture, String filename,
                                 ImageFormatHandler.ImageFormatTypes format)
 {
     Capture(typeOfCapture);
     Save(filename, format);
     return(images);
 }
示例#2
0
 /// <summary>
 /// Capture a specific form and save it into a file.
 /// </summary>
 /// <param name="window">This is the desired window which should be captured.</param>
 /// <param name="filename">The name of the target file. The extension in there is ignored,
 /// it will replaced by an extension derived from the desired file format.</param>
 /// <param name="format">The format of the file.</param>
 /// <param name="onlyClient">When set to 'true' then only the client area of the form is captured,
 /// otherwise the complete window with title bar, frame etc. is captured.</param>
 /// <returns>The image which has been captured.</returns>
 public virtual Bitmap Capture(Form window, String filename, ImageFormatHandler.ImageFormatTypes format,
                               bool onlyClient)
 {
     Capture(window, onlyClient);
     Save(filename, format);
     return(images[0]);
 }
示例#3
0
        /// <summary>
        /// Save all captured screens into a file.
        /// </summary>
        /// <param name="filename">The name of the target file. The extension in there is ignored,
        /// it will replaced by an extension derived from the desired file format.</param>
        /// <param name="format">The format of the file.</param>
        /// <returns>An array of images captured.</returns>
        public virtual void Save(String filename, ImageFormatHandler.ImageFormatTypes format)
        {
            String directory = Path.GetDirectoryName(filename);
            String name      = Path.GetFileNameWithoutExtension(filename);
            String ext;

            ext = formatHandler.GetDefaultFilenameExtension(format);

            if (ext.Length == 0)
            {
                format = ImageFormatHandler.ImageFormatTypes.imgPNG;
                ext    = "png";
            }

            try
            {
                ImageCodecInfo    info;
                EncoderParameters parameters = formatHandler.GetEncoderParameters(format, out info);

                for (int i = 0; i < images.Length; i++)
                {
                    if (images.Length > 1)
                    {
                        filename = String.Format("{0}\\{1}.{2:D2}.{3}", directory, name, i + 1, ext);
                    }
                    else
                    {
                        filename = String.Format("{0}\\{1}.{2}", directory, name, ext);
                    }
                    image = images[i];

                    if (parameters != null)
                    {
                        image.Save(filename, info, parameters);
                    }
                    else
                    {
                        image.Save(filename, ImageFormatHandler.GetImageFormat(format));
                    }
                }
            }
            catch (Exception ex)
            {
                string s =
                    string.Format("Saving image to [{0}] in format [{1}].\n{2}", filename, format, ex);
                MessageBox.Show(s, "Capture failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#4
0
        public virtual void Save(string filename, ImageFormatHandler.ImageFormatTypes format)
        {
            string directoryName            = Path.GetDirectoryName(filename);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
            string extension = Path.GetExtension(filename);

            extension = this.imageFormatHandler_0.GetDefaultFilenameExtension(format);
            if (extension.Length == 0)
            {
                format    = ImageFormatHandler.ImageFormatTypes.imgPNG;
                extension = "png";
            }
            try
            {
                ImageCodecInfo    info;
                EncoderParameters encoderParameters = this.imageFormatHandler_0.GetEncoderParameters(format, out info);
                for (int i = 0; i < this.bitmap_1.Length; i++)
                {
                    if (this.bitmap_1.Length > 1)
                    {
                        filename = string.Format(@"{0}\{1}.{2:D2}.{3}", new object[] { directoryName, fileNameWithoutExtension, i + 1, extension });
                    }
                    else
                    {
                        filename = string.Format(@"{0}\{1}.{2}", directoryName, fileNameWithoutExtension, extension);
                    }
                    this.bitmap_0 = this.bitmap_1[i];
                    if (encoderParameters != null)
                    {
                        this.bitmap_0.Save(filename, info, encoderParameters);
                    }
                    else
                    {
                        this.bitmap_0.Save(filename, ImageFormatHandler.GetImageFormat(format));
                    }
                }
            }
            catch (Exception exception)
            {
                string.Format("Saving image to [{0}] in format [{1}].\n{2}", filename, format.ToString(), exception.ToString());
            }
        }
示例#5
0
 /// <summary>
 /// 截取指定的窗体并保存到指定的文件中
 /// </summary>
 /// <param name="window">待截图的窗体</param>
 /// <param name="filename">目标文件名称。此处忽略文件后缀名,后缀名根据图片文件格式而定。</param>
 /// <param name="format">文件格式</param>
 /// <returns>截取的图片对象</returns>
 public virtual Bitmap Capture(Form window, String filename, ImageFormatHandler.ImageFormatTypes format)
 {
     return(Capture(window, filename, format, false));
 }
示例#6
0
 public virtual Bitmap CaptureControl(Control window, string filename, ImageFormatHandler.ImageFormatTypes format)
 {
     this.CaptureControl(window);
     this.Save(filename, format);
     return(this.bitmap_1[0]);
 }
示例#7
0
 public virtual Bitmap[] Capture(CaptureType typeOfCapture, string filename, ImageFormatHandler.ImageFormatTypes format)
 {
     this.Capture(typeOfCapture);
     this.Save(filename, format);
     return(this.bitmap_1);
 }
示例#8
0
文件: Form1.cs 项目: takkkken/ssicat
 private void radiobuttonGIF_CheckedChanged(object sender, EventArgs e)
 {
     if (radiobuttonGIF.Checked)
     {
         selectedImageFormat = ImageFormatHandler.ImageFormatTypes.imgGIF;
         selectedImageFormatExtension = ".gif";
     }
 }
示例#9
0
文件: Form1.cs 项目: takkkken/ssicat
 public void defaultSettings()
 {
     serverAddress = ":21";
     username = "";
     password = "";
     path = "/";
     urlEnable = false;
     passiveOn = true;
     urlToImages = "";
     imagePrefix = "sicatimage";
     count = 1;
     imageFormat = ImageFormatHandler.ImageFormatTypes.imgJPEG;
     imageFormatExt = ".jpg";
     capType = ScreenCapture.CaptureType.PrimaryScreen;
     hotkey = Keys.PrintScreen;
 }
示例#10
0
 public virtual Bitmap Capture(IntPtr handle, string filename, ImageFormatHandler.ImageFormatTypes format)
 {
     this.Capture(handle);
     this.Save(filename, format);
     return(this.bitmap_1[0]);
 }
示例#11
0
文件: Form1.cs 项目: takkkken/ssicat
        public formConfiguration()
        {
            InitializeComponent();
            if (File.Exists(FILE_NAME))
            {
                Stream input = File.OpenRead(FILE_NAME);
                BinaryFormatter bRead = new BinaryFormatter();
                settings = (SettingsFile)bRead.Deserialize(input);
                input.Close();
                try
                {
                    String[] address = settings.serverAddress.Split(new Char[] { ':' });
                    textboxServerAddress.Text = address[0];
                    try
                    {
                        textboxPort.Text = address[1];
                    }
                    catch
                    {
                        textboxPort.Text = "21";
                    }
                    textboxUsername.Text = settings.username;
                    textboxPassword.Text = settings.password;
                    textboxPath.Text = settings.path;
                    checkboxEnable.Checked = settings.urlEnable;
                    passive_on.Checked = settings.passiveOn;

                    textboxURLToImages.Text = settings.urlToImages;
                    logRecord = settings.log;
                    textboxPrefix.Text = settings.imagePrefix;
                    count = settings.count;
                    selectedImageFormat = settings.imageFormat;
                    selectedImageFormatExtension = settings.imageFormatExt;
                    selectedCapType = settings.capType;
                }
                catch
                {
                    MessageBox.Show("Failed to load settings file.\nBackup created; using default settings.");
                    File.Copy(FILE_NAME, "settings_backup.dat");
                    settings = new SettingsFile();
                    String[] address = settings.serverAddress.Split(new Char[] { ':' });
                    textboxPort.Text = address[1];
                    textboxPath.Text = settings.path;
                    textboxPrefix.Text = settings.imagePrefix;
                    count = settings.count;
                    selectedImageFormat = settings.imageFormat;
                    selectedImageFormatExtension = settings.imageFormatExt;
                    selectedCapType = settings.capType;
                }
            }
            else
            {
                settings = new SettingsFile();
                String[] address = settings.serverAddress.Split(new Char[] { ':' });
                textboxPort.Text = address[1];
                textboxPath.Text = settings.path;
                textboxPrefix.Text = settings.imagePrefix;
                count = settings.count;
                selectedImageFormat = settings.imageFormat;
                selectedImageFormatExtension = settings.imageFormatExt;
                selectedCapType = settings.capType;
            }
            hotkey = settings.hotkey;
            modkeys = settings.modkeys;
            modifiers = settings.modifiers;
            RegisterGlobalHotKey(hotkey, modifiers);
            if(modkeys.ToString().Equals("None"))
                labelCurrentHotkey.Text = hotkey.ToString();
            else
                labelCurrentHotkey.Text = modkeys.ToString() + " + " + hotkey.ToString();
            setRadioButtons();
        }
示例#12
0
文件: Form1.cs 项目: takkkken/ssicat
        private void resetSettings()
        {
            String[] address = settings.serverAddress.Split(new Char[] { ':' });
            textboxServerAddress.Text = address[0];
            try
            {
                textboxPort.Text = address[1];
            }
            catch
            {
                textboxPort.Text = "21";
            }
            textboxUsername.Text = settings.username;
            textboxPassword.Text = settings.password;
            textboxPath.Text = settings.path;
            checkboxEnable.Checked = settings.urlEnable;
            passive_on.Checked = settings.passiveOn;

            textboxURLToImages.Text = settings.urlToImages;
            textboxPrefix.Text = settings.imagePrefix;
            selectedImageFormat = settings.imageFormat;
            selectedImageFormatExtension = settings.imageFormatExt;
            selectedCapType = settings.capType;
            UnregisterGlobalHotKey();
            hotkey = settings.hotkey;
            modkeys = settings.modkeys;
            modifiers = settings.modifiers;
            if(modkeys.ToString().Equals("None"))
                labelCurrentHotkey.Text = hotkey.ToString();
            else
                labelCurrentHotkey.Text = modkeys.ToString() + " + " + hotkey.ToString();
            RegisterGlobalHotKey(hotkey, modifiers);
            setRadioButtons();
        }
示例#13
0
文件: Form1.cs 项目: takkkken/ssicat
 private void radiobuttonPNG_CheckedChanged(object sender, EventArgs e)
 {
     if (radiobuttonPNG.Checked)
     {
         selectedImageFormat = ImageFormatHandler.ImageFormatTypes.imgPNG;
         selectedImageFormatExtension = ".png";
     }
 }
示例#14
0
 /// <summary>
 /// 截取指定窗体(通过句柄)并保存到指定的文件中
 /// </summary>
 /// <param name="handle">待截图的窗体句柄</param>
 /// <param name="filename">目标文件名称。此处忽略文件后缀名,后缀名根据图片文件格式而定。</param>
 /// <param name="format">文件格式</param>
 /// <returns>截取的图片对象</returns>
 public virtual Bitmap Capture(IntPtr handle, String filename, ImageFormatHandler.ImageFormatTypes format)
 {
     Capture(handle);
     Save(filename, format);
     return(images[0]);
 }
示例#15
0
 public virtual Bitmap Capture(Form window, string filename, ImageFormatHandler.ImageFormatTypes format, bool onlyClient)
 {
     this.Capture(window, onlyClient);
     this.Save(filename, format);
     return(this.bitmap_1[0]);
 }
示例#16
0
 /// <summary>
 /// 截取窗体客户区域中指定的控件截图
 /// </summary>
 /// <param name="window">待截图的控件</param>
 /// <param name="filename">The name of the target file. The extension in there is ignored,
 /// it will replaced by an extension derived from the desired file format.</param>
 /// <param name="format">The format of the file.</param>
 /// <returns>The image which has been captured.</returns>
 public virtual Bitmap CaptureControl(System.Windows.Forms.Control window, String filename, ImageFormatHandler.ImageFormatTypes format)
 {
     CaptureControl(window);
     Save(filename, format);
     return(images[0]);
 }
示例#17
0
文件: Form1.cs 项目: takkkken/ssicat
 private void radiobuttonBMP_CheckedChanged(object sender, EventArgs e)
 {
     if (radiobuttonBMP.Checked)
     {
         selectedImageFormat = ImageFormatHandler.ImageFormatTypes.imgBMP;
         selectedImageFormatExtension = ".bmp";
     }
 }