Esempio n. 1
0
File: Core.cs Progetto: zzattack/NFU
        /// <summary>
        /// Take a screenshot to upload.
        /// </summary>
        private void ButtonScreenshot(object sender, EventArgs e)
        {
            if (Snipper.IsActive)
            {
                return;
            }

            _screenshot = Snipper.Snip();

            if (_screenshot != null)
            {
                reuploadScreenshotToolStripMenuItem.Enabled = true;

                switch (Snipper.ReturnType)
                {
                case Snipper.ReturnTypes.Default:
                    Uploader.UploadImage(_screenshot);
                    break;

                case Snipper.ReturnTypes.ToClipboard:
                    Clipboard.SetImage(_screenshot);
                    Misc.ShowInfo(Resources.ScreenShotCopiedTitle, Resources.ScreenShotCopied);
                    break;
                }
            }
            else
            {
                Misc.HandleError(new ArgumentException(Resources.NoFilesSelected), Resources.ScreenShot);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Snips the image.
        /// </summary>
        /// <returns>The image or null on failure.</returns>
        public static Image Snip()
        {
            IsActive = true;

            Program.FormCore.Opacity = 0;

            var rectangleFullScreen = SystemInformation.VirtualScreen;

            _bitmapFullScreen = new Bitmap(rectangleFullScreen.Width, rectangleFullScreen.Height, PixelFormat.Format32bppRgb);
            _offsetX          = (rectangleFullScreen.X < 0) ? rectangleFullScreen.X * -1 : 0;
            _offsetY          = (rectangleFullScreen.Y < 0) ? rectangleFullScreen.Y * -1 : 0;

            using (var gr = Graphics.FromImage(_bitmapFullScreen))
            {
                // TODO: Fix this hack
                // Somehow, the color #0D0B0C (13, 11, 12) becomes a transparent pixel, or a black pixel if there is no alpha channel
                // This doesn't happen if the graphics object is cleared using this color first, however, this is a bit hacky (why only this color)
                gr.Clear(Color.FromArgb(13, 11, 12));
                gr.CopyFromScreen(rectangleFullScreen.X, rectangleFullScreen.Y, 0, 0, _bitmapFullScreen.Size);
            }

            using (var snipper = new Snipper())
            {
                var result = snipper.ShowDialog();
                Program.FormCore.Opacity = 1;
                IsActive = false;

                if (result == DialogResult.OK)
                {
                    return(snipper._image);
                }
            }

            return(null);
        }