Ejemplo n.º 1
0
        private static Bitmap BuildImgFullScreen(ref ScreenshotData screenshotData)
        {
            if (screenshotData.ImgSize.Width <= 0 || screenshotData.ImgSize.Height <= 0)
                return null;

            screenshotData.StartDate = DateTime.Now;

            Win32Helper.SIZE size;

            var hDC = Win32Helper.GetDC(Win32Helper.GetDesktopWindow());
            var hMemDC = Win32Helper.CreateCompatibleDC(hDC);

            size.x = Win32Helper.GetSystemMetrics(Win32Helper.SM_CXSCREEN);
            size.y = Win32Helper.GetSystemMetrics(Win32Helper.SM_CYSCREEN);

            var m_HBitmap = Win32Helper.CreateCompatibleBitmap(hDC, size.x, size.y);

            if (m_HBitmap == IntPtr.Zero)
                return null;

            var hOld = Win32Helper.SelectObject(hMemDC, m_HBitmap);
            Win32Helper.BitBlt(hMemDC, 0, 0, size.x, size.y, hDC, 0, 0, Win32Helper.SRCCOPY);
            Win32Helper.SelectObject(hMemDC, hOld);
            Win32Helper.DeleteDC(hMemDC);
            Win32Helper.ReleaseDC(Win32Helper.GetDesktopWindow(), hDC);

            return Image.FromHbitmap(m_HBitmap);
        }
Ejemplo n.º 2
0
        public PictureData(Bitmap img, ScreenshotData screenshotData)
        {
            this.Picture = img;
            this.screenshotData = screenshotData;
            this.screenshotData.ImgSize = new Rectangle(Point.Empty, this.Picture.Size);

            this.Initialize();
        }
Ejemplo n.º 3
0
        public static Bitmap CaptureRegion(ref ScreenshotData screenshotData)
        {
            SelectorView.Initialize();

            var background = CaptureScreen(ref screenshotData);
            screenshotData.ImgSize = SelectorView.Showing(background);
            return BuildImg(ref screenshotData, background);
        }
Ejemplo n.º 4
0
        private static Bitmap BuildImg(ref ScreenshotData screenshotData, Bitmap background = null)
        {
            if (screenshotData.ImgSize.Width <= 0 || screenshotData.ImgSize.Height <= 0)
                return null;

            screenshotData.StartDate = DateTime.Now;

            var screen = background ?? new Bitmap(MonitorService.VirtualWidth, MonitorService.VirtualHeight);
            var selection = new Bitmap(screenshotData.ImgSize.Width, screenshotData.ImgSize.Height, PixelFormat.Format32bppRgb);

            var g = Graphics.FromImage(selection);
            g.CopyFromScreen(screenshotData.ImgSize.Left + MonitorService.VirtualLeft, screenshotData.ImgSize.Top + MonitorService.VirtualTop, 0, 0, new Size(screenshotData.ImgSize.Width, screenshotData.ImgSize.Height), CopyPixelOperation.SourceCopy);
            g.DrawImage(screen, 0, 0, screenshotData.ImgSize, GraphicsUnit.Pixel);

            return selection;
        }
Ejemplo n.º 5
0
        public static async void StatUpload(ScreenshotData screenData)
        {
            const string url = "https://noelpush.com/add_upload";

            var values = new Dictionary<string, string>
            {
                { "uid", screenData.UserId },
                { "version", screenData.Version },
                { "url", screenData.uRL },
                { "mode", screenData.Mode.ToString(CultureInfo.InvariantCulture) },
                { "png_filesize", screenData.PngSize.ToString(CultureInfo.InvariantCulture) },
                { "jpeg_filesize", screenData.JpegSize.ToString(CultureInfo.InvariantCulture) },
                { "width", screenData.ImgSize.Width.ToString(CultureInfo.InvariantCulture) },
                { "height", screenData.ImgSize.Height.ToString(CultureInfo.InvariantCulture) },
                { "upload_delay",  ((int)(screenData.StopUpload - screenData.StartUpload).TotalMilliseconds).ToString(CultureInfo.InvariantCulture) },
                { "total_delay",  ((int)(screenData.StopUpload - screenData.StartDate).TotalMilliseconds).ToString(CultureInfo.InvariantCulture) },
                { "second_press_delay", (screenData.SecondPressDate == DateTime.MinValue ? -1 : (int)(screenData.SecondPressDate - screenData.FirstPressDate).TotalMilliseconds).ToString(CultureInfo.InvariantCulture) },
                { "third_press_delay", (screenData.ThirdPressDate == DateTime.MinValue ? -1 : (int)(screenData.ThirdPressDate - screenData.SecondPressDate).TotalMilliseconds).ToString(CultureInfo.InvariantCulture) },
            };

            await RequestService.SendRequest(url, values);
        }
Ejemplo n.º 6
0
        public async void UploadTask(Bitmap picture, ScreenshotData screenshotData)
        {
            // Upload only if a jpeg has been uploaded
            if (screenshotData.Format == "png")
                return;

            this.userId = screenshotData.UserId;
            this.firstUrl = screenshotData.uRL;

            var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\NoelPush\Sending\";
            
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path += DateTime.Now.ToString(@"yyyy-MM-dd-HH\hmm\mss\s") + ".png";
            await CreatePng(picture, path);

            var dataBytes = File.ReadAllBytes(path);

            new UploaderService().Upload(this, path, dataBytes, path.Split('.').Last());
        }
Ejemplo n.º 7
0
 public void Upload(Bitmap picture, ScreenshotData screenshotData)
 {
     UploadTask(picture, screenshotData);
 }
Ejemplo n.º 8
0
 public static Bitmap CaptureScreen(ref ScreenshotData screenshotData)
 {
     screenshotData.ImgSize = new Rectangle(0, 0, MonitorService.VirtualWidth, MonitorService.VirtualHeight);
     return BuildImg(ref screenshotData);
 }
Ejemplo n.º 9
0
 public static Bitmap CaptureFullScreen(ref ScreenshotData screenshotData)
 {
     screenshotData.ImgSize = new Rectangle(0, 0, MonitorService.CurrentWidth, MonitorService.CurrentHeight);
     return BuildImgFullScreen(ref screenshotData);
 }
Ejemplo n.º 10
0
        // Disabled for R15
        //private void Capture(object sender, ShortcutEventArgs e)
        //{
        //    this.Capture();
        //}
        public void Capture(bool upload = true)
        {
            var date = DateTime.Now;
            this.pressCounter++;

            // First press or bad time
            if (this.pressCounter <= 1 || (this.pressCounter > 1 && date > this.pressDateTime.AddMilliseconds(400)))
            {
                this.ScreenData = new ScreenshotData(this.UserId);

                this.pressCounter = 1;
                this.CancelCapture();
                this.pressDateTime = DateTime.Now;
            }

            // Second press
            else if (this.pressCounter == 2)
            {
                this.ScreenData.Mode = 1;
                this.ScreenData.SecondPressDate = DateTime.Now;
                this.ScreenData.ThirdPressDate = DateTime.MinValue;

                this.pressDateTime = DateTime.Now;

                Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => this.CaptureRegion(this.ScreenData, upload)));

                // Disabled for R15
                //if (FullScreenHelper.IsFullScreen)
                //{
                //    new SoundPlayer(Resources.notif2).Play();
                //    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => this.CaptureFullScreen(this.ScreenData, upload)));
                //    this.pressCounter = 0;
                //}
            }

            // Third press
            if (this.pressCounter == 3)
            {
                this.ScreenData.Mode = 2;
                this.ScreenData.ThirdPressDate = DateTime.Now;

                this.CancelCapture();
                Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => this.CaptureScreen(this.ScreenData, upload)));
                this.pressCounter = 0;
            }
        }
Ejemplo n.º 11
0
        private void CaptureFullScreen(ScreenshotData data, bool upload)
        {
            var capture = CaptureService.CaptureFullScreen(ref data);

            if (capture != null)
                this.Captured(capture, data, upload);
        }
Ejemplo n.º 12
0
        public void Uploaded(Bitmap img, string url, ScreenshotData screenshotData, bool error)
        {
            if (!error)
            {
                Application.Current.Dispatcher.Invoke(() => Clipboard.SetText(url));
                this.notifyIconViewModel.EnableCommands(true);
                this.notifyIconViewModel.ShowPopupUpload(img);
            }
            else
            {
                this.UploadFailed();
            }

            screenshotData.uRL = url;

            StatisticsService.StatUpload(screenshotData);
            // Disable temporary
            //new DualFormatService().Upload(img, screenshotData);
        }
Ejemplo n.º 13
0
        public void CaptureRegion(ScreenshotData data, bool upload)
        {
            var capture = CaptureService.CaptureRegion(ref data);

            if (capture != null)
                this.Captured(capture, data, upload);
        }
Ejemplo n.º 14
0
        public void Captured(Bitmap img, ScreenshotData screenshotData, bool upload)
        {
            this.pressCounter = 0;

            if (upload)
            {
                this.notifyIconViewModel.EnableCommands(false);
                var pictureData = new PictureData(img, screenshotData);
                new UploaderService(this).Upload(pictureData);
            }
            else
            {
                Application.Current.Dispatcher.Invoke(() => Clipboard.SetImage(CreateBitmapSourceFromBitmap(img)));
                this.notifyIconViewModel.ShowPopupCopy(img);
            }
        }