Пример #1
1
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    this.Hide();
                    // This gives time to the Form to hide before it takes the screenshot. 500 miliseconds are enough.
                    Thread.Sleep(500);
                    // Set the image to the size of the screen.
                    bt = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                    // Creates the graphic object for the image (bt).
                    screenShot = Graphics.FromImage(bt);
                    // Takes the screenshot.
                    screenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size,

                CopyPixelOperation.SourceCopy);
                    switch (saveFileDialog1.FilterIndex)
                    {
                        case 0: img = ImageFormat.Bmp; break;
                        case 1: img = ImageFormat.Png; break;
                        case 2: img = ImageFormat.Jpeg; break;
                    }
                    // Saves the image.
                    bt.Save(saveFileDialog1.FileName, img);
                    // After the screenshot is taken the Form reappears.
                    this.Show();
                }
            }

            catch (Exception i)
            {
                MessageBox.Show("Error: "+i.Message);
            }
        }
Пример #2
0
        bool capture_image_is_moving()
        {
            if (points == null)
            {
                points = new Color[3, 3];
            }

            bool ret = false;

            System.Drawing.Bitmap BM = new System.Drawing.Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

            System.Drawing.Bitmap   BM1 = new System.Drawing.Bitmap(1, 1);
            System.Drawing.Graphics GH  = System.Drawing.Graphics.FromImage(BM1 as System.Drawing.Image);

            int incI = 0;
            int incJ = 0;

            for (int i = BM.Width / 6; i < BM.Width; i = i + BM.Width / 3)
            {
                incJ = 0;
                for (int j = BM.Height / 6; j < BM.Height; j = j + BM.Height / 3)
                {
                    GH.CopyFromScreen(i, j, 0, 0, BM1.Size);
                    Color col = BM1.GetPixel(0, 0);
                    if (points[incI, incJ] != col)
                    {
                        ret = true;
                    }
                    incJ++;
                }
                incI++;
            }

            incI = 0;
            incJ = 0;
            for (int i = BM.Width / 6; i < BM.Width; i = i + BM.Width / 3)
            {
                incJ = 0;
                for (int j = BM.Height / 6; j < BM.Height; j = j + BM.Height / 3)
                {
                    GH.CopyFromScreen(i, j, 0, 0, BM1.Size);
                    points[incI, incJ] = BM1.GetPixel(0, 0);

                    incJ++;
                }
                incI++;
            }
            GH.Dispose();

            return(ret);
        }
 private void MyScreenShoot()
 {
     size        = new Size(200, 200);
     memoryImage = new Bitmap(800, 800);
     System.Drawing.Graphics memoryGraphics = System.Drawing.Graphics.FromImage(memoryImage);
     memoryGraphics.CopyFromScreen(500, 500, 0, 0, size);
 }
Пример #4
0
    public byte[] PCScreen()
    {
        //Thread.Sleep(200);
        System.Drawing.Bitmap bitmap = new Bitmap(Screen.width, Screen.height);

        System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); //创建画笔

        graphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), bitmap.Size);       //截屏

        string fileName = Application.streamingAssetsPath + "/PCScreen.jpg";

        bitmap.Save(fileName);

        //将图片读回成数组
        FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

        fileStream.Seek(0, SeekOrigin.Begin);
        byte[] bytes = new byte[fileStream.Length];
        fileStream.Read(bytes, 0, (int)fileStream.Length);

        //释放文件读取流
        fileStream.Close();
        fileStream.Dispose();
        fileStream = null;
        bitmap.Dispose();
        graphics.Dispose();

        return(bytes);
    }
Пример #5
0
        private void picker_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (isPickering)
            {
                var p      = GlobalMouse.Position;
                int offset = 50;
                if (cp != null)
                {
                    bmp = new System.Drawing.Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    System.Drawing.Graphics gph = System.Drawing.Graphics.FromImage(bmp);
                    gph.CopyFromScreen((int)p.X - offset, (int)p.Y - offset, 0, 0, new System.Drawing.Size(100, 100));

                    var color = bmp.GetPixel(offset, offset);
                    pixelColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
                    gph.Dispose();

                    double eX = p.X;
                    double eY = p.Y;
                    double X = eX + 10, Y = eY + 10;
                    if (X + cp.Width + 10 > SystemParameters.PrimaryScreenWidth)
                    {
                        X = eX - (cp.Width + 10);
                    }
                    if (Y + cp.Height + 10 > SystemParameters.PrimaryScreenHeight)
                    {
                        Y = eY - (cp.Height + 10);
                    }
                    cp.Left = X;
                    cp.Top  = Y;
                    int w = ((88 - pixel) / 2 / pixel * pixel * 2) + pixel;
                    int h = ((88 - pixel) / 2 / pixel * pixel * 2) + pixel;
                    ChangePosition(offset, offset, w, h, pixel);
                }
            }
        }
Пример #6
0
        //helper function
        private void TakeScreenShot()
        {
            // Create an empty Bitmap to store the screen shot
            Bitmap screenshotBmp;

            screenshotBmp = new System.Drawing.Bitmap((int)(myImgPanel.ActualWidth * factor), (int)(myImgPanel.ActualHeight * factor), System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            // Get a graphics context from the empty bitmap
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(screenshotBmp))
            {
                g.CopyFromScreen((int)(this.Left * factor), (int)((this.Top + myTitle.ActualHeight) * factor), 0, 0, screenshotBmp.Size);
            }

            IntPtr handle = IntPtr.Zero;

            try
            {
                // Get the GDI andle for the Bitmap
                handle = screenshotBmp.GetHbitmap();

                // convert from the .NET image format to the WPF image format
                imageWindow.capturedImg.Source = Imaging.CreateBitmapSourceFromHBitmap(handle,
                                                                                       IntPtr.Zero, Int32Rect.Empty,
                                                                                       BitmapSizeOptions.FromEmptyOptions());
            }
            finally
            {
                DeleteObject(handle);
            }
            imageWindow.StoreImage();
            imageWindow.Show();
        }
Пример #7
0
        private void ScreenshotButton_Click(object sender, RoutedEventArgs e)
        {
            int Top  = (int)this.Top;
            int Left = (int)this.Left;

            int Width  = (int)this.Width;
            int Height = (int)this.Height;

            using (Bitmap bmpScreenCapture = new Bitmap(Width,
                                                        Height))
            {
                using (System.Drawing.Graphics g = Graphics.FromImage(bmpScreenCapture))
                {
                    g.CopyFromScreen(Left,
                                     Top,
                                     0, 0,
                                     bmpScreenCapture.Size,
                                     CopyPixelOperation.SourceCopy);

                    // Write out the bitmap here encoded by a time-stamp?
                    String fname = output_root + DateTime.Now.ToString("yyyy-MMM-dd--HH-mm-ss") + ".png";
                    bmpScreenCapture.Save(fname, ImageFormat.Png);
                }
            }
        }
Пример #8
0
 /// <summary>
 /// true-黑色字体,false-白色字体
 /// </summary>
 /// <returns></returns>
 public static Task <bool> IsBlack(double Left, double Top, double Width, double Height)
 {
     return(Task.Run(() =>
     {
         Drawing.Rectangle[] rectangles = new Drawing.Rectangle[] {
             new Drawing.Rectangle((int)Left, (int)Top, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight),
             new Drawing.Rectangle((int)Left + (int)Width / 2, (int)Top + (int)Height / 2, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight),
             new Drawing.Rectangle((int)Left + (int)Width, (int)Top + (int)Height, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight)
         };
         int counter = 0;
         foreach (var rc in rectangles)
         {
             var bitmap = new Drawing.Bitmap(1, 1);
             using (Drawing.Graphics g = Drawing.Graphics.FromImage(bitmap))
             {
                 g.CopyFromScreen((int)(rc.X * Settings.Default.dpi), (int)(rc.Y * Settings.Default.dpi), 0, 0, rc.Size, Drawing.CopyPixelOperation.SourceCopy);
             }
             Drawing.Color color = bitmap.GetPixel(0, 0);
             bitmap.Dispose();
             if (color.R + color.G + color.B > 384)
             {
                 counter++;
             }
         }
         return counter >= ((double)rectangles.Length) / 2;
     }));
 }
Пример #9
0
 public static Bitmap takeSnapshot(Control ctl)
 {
     Bitmap bmp = new Bitmap(ctl.Size.Width, ctl.Size.Height);
     System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
     g.CopyFromScreen(ctl.PointToScreen(ctl.ClientRectangle.Location), new Point(0, 0), ctl.ClientRectangle.Size);
     return bmp;
 }
Пример #10
0
        private void CaptureScreen(double x, double y, double width, double height)
        {
            int ix = Convert.ToInt32(x);
            int iy = Convert.ToInt32(y);
            int iw = Convert.ToInt32(width);
            int ih = Convert.ToInt32(height);

            if (iw == 0 || ih == 0)
            {
                return;                     // 规避 System.ArgumentException 异常
            }
            System.Drawing.Bitmap bitmap = new Bitmap(iw, ih);
            using (System.Drawing.Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.CopyFromScreen(ix, iy, 0, 0, new System.Drawing.Size(iw, ih));



                Clipboard.SetDataObject(bitmap, true);


                //  SaveFileDialog dialog = new SaveFileDialog();
                //dialog.Filter = "Png Files|*.png";
                //if (dialog.ShowDialog() ==  System.Windows.Forms.DialogResult.OK
                {
                    //    bitmap.Save(dialog.FileName, ImageFormat.Png);
                }
            }
        }
    public int[] PixelSearch(int x1, int y1, int width, int height, int color, int range, int Step)
    {
        //int width = x2 - x1;
        //int height = y2 - y1;
        if (Step < 1)
        {
            Step = 1;
        }
        int[] rv = new int[2];
        rv[0] = -1;
        //FileFunctions.fConsoleWrite("x:" + x1.ToString() + " y:" +
        //    y1.ToString());
        Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(bmp);
        GFX.CopyFromScreen(x1, y1, 0, 0, new Size(width, height), System.Drawing.CopyPixelOperation.SourceCopy);
        Color bColor = new Color();

        for (int by = 0; by < bmp.Height && rv[0] == -1; by += Step)
        {
            for (int bx = 0; bx < bmp.Width && rv[0] == -1; bx += Step)
            {
                bColor = bmp.GetPixel(bx, by);
                string sColor = bColor.ToArgb().ToString("X8").Substring(2, 6);
                int    iColor = System.Int32.Parse(sColor, System.Globalization.NumberStyles.AllowHexSpecifier);
                if (_ColorRange(iColor, color, range))
                {
                    rv[0] = x1 + bx;
                    rv[1] = y1 + by;
                }
            }
        }
        return(rv);
    }
Пример #12
0
        public static List <string> GetScreenshotFiles(string file, System.Drawing.Imaging.ImageFormat format)
        {
            List <string> files = new List <string>();

            foreach (System.Windows.Forms.Screen s in System.Windows.Forms.Screen.AllScreens)
            {
                string f;
                if (s.Primary)
                {
                    f = file;
                }
                else
                {
                    f = PathRoutines.InsertSuffixBeforeFileExtension(file, "_" + PathRoutines.GetLegalizedFileName(s.DeviceName));
                }
                System.Drawing.Rectangle bounds = s.Bounds;
                using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(bounds.Width, bounds.Height))
                {
                    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
                    }
                    bitmap.Save(f, format);
                }
                files.Add(f);
            }
            return(files);
        }
Пример #13
0
        public GemBoard readScreen()
        {
            GemBoard gemBoard = new GemBoard();

            int width  = boardPosition.getWidth();
            int height = boardPosition.getHeight();
            int x1     = boardPosition.getX1();
            int y1     = boardPosition.getY1();

            using (sDrawing.Bitmap screenBmp = new sDrawing.Bitmap(width, height + 50, sDrawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (sDrawing.Graphics bmpGraphics = sDrawing.Graphics.FromImage(screenBmp))
                {
                    bmpGraphics.CopyFromScreen(x1, y1, 0, 0, screenBmp.Size);
                }

                for (int gridX = 0; gridX < 8; gridX++)
                {
                    for (int gridY = 0; gridY < 8; gridY++)
                    {
                        int screenX;
                        int screenY;
                        boardPosition.gridToScreenOffset(gridX, gridY, out screenX, out screenY);
                        wMedia.Color color = colorFromBitmap(screenBmp, screenX, screenY);
                        gemBoard.setColor(gridX, gridY, color);
                    }
                }
            }
            return(gemBoard);
        }
Пример #14
0
 public Bitmap CaptureScreen(int x, int y, Size size, bool useGDI)
 {
     if (_testScreenshot != null)
     {
         return(BitmapProcessor.Copy(_testScreenshot, new Rectangle(new Point(x, y), size)));
     }
     else if (useGDI)
     {
         IntPtr hDesk   = GetDesktopWindow();
         IntPtr hSrce   = GetWindowDC(hDesk);
         IntPtr hDest   = CreateCompatibleDC(hSrce);
         IntPtr hBmp    = CreateCompatibleBitmap(hSrce, size.Width, size.Height);
         IntPtr hOldBmp = SelectObject(hDest, hBmp);
         bool   b       = BitBlt(hDest, 0, 0, size.Width, size.Height, hSrce, x, y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
         Bitmap bmp     = Bitmap.FromHbitmap(hBmp);
         SelectObject(hDest, hOldBmp);
         DeleteObject(hBmp);
         DeleteDC(hDest);
         ReleaseDC(hDesk, hSrce);
         return(bmp);
     }
     else
     {
         Bitmap memoryImage = new Bitmap(size.Width, size.Height);
         System.Drawing.Graphics memoryGraphics = System.Drawing.Graphics.FromImage(memoryImage);
         memoryGraphics.CopyFromScreen(x, y, 0, 0, size);
         return(memoryImage);
     }
 }
        /// <summary>
        /// Captures the screen.
        /// </summary>
        private void captureScreen()
        {
            Point p = Control.MousePosition;

            p.X -= bmpScreenCapture.Width / 2;
            p.Y -= bmpScreenCapture.Height / 2;

            using (System.Drawing.Graphics dc = System.Drawing.Graphics.FromImage(bmpScreenCapture))
            {
                dc.CopyFromScreen(p, new Point(0, 0), bmpScreenCapture.Size);

                Color c = bmpScreenCapture.GetPixel(
                    (int)(bmpScreenCapture.Size.Width / 2.0F),
                    (int)(bmpScreenCapture.Size.Height / 2.0F));
                if (c != _SelectedColor)
                {
                    _SelectedColor = c;
                    if (SelectedColorChanged != null)
                    {
                        SelectedColorChanged(this, null);
                    }
                }

                if (_ShowPixelPreview || _ShowColorPreview)
                {
                    if (pixelZoom == null)
                    {
                        pixelZoom = new PixelZoom(this);
                    }
                    pixelZoom.PaintScreenCapture(bmpScreenCapture);
                }
                OnScreenCaptured();
            }
        }
Пример #16
0
        public Bitmap CreateBitmapFromScreen(Size sSize, Point pLocation)
        {
            try
            {
                if (sSize != null && pLocation != null && !sSize.IsEmpty)
                {
                    Bitmap bmap = new Bitmap(sSize.Width, sSize.Height, mPixFor);
                    if (bmap != null)
                    {
                        System.Drawing.Graphics gFX = Graphics.FromImage(bmap);
                        if (gFX != null)
                        {
                            gFX.CopyFromScreen(pLocation.X, pLocation.Y, 0, 0, sSize, CopyPixelOperation.SourceCopy);

                            return(bmap);
                        }
                    }
                }
                return(null);
            } catch (Exception ex)
            {
                Log.Logger.Log("CreateBitmapFromScreen", ex);
                return(null);
            }
        }
        private void ScreenshotButton_Click(object sender, RoutedEventArgs e)
        {
            PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);

            var topLeft     = source.CompositionTarget.TransformToDevice.Transform(new System.Windows.Point(this.Left, this.Top));
            var bottomRight = source.CompositionTarget.TransformToDevice.Transform(new System.Windows.Point(this.Left + this.Width, this.Top + this.Height));

            int Width  = (int)(bottomRight.X - topLeft.X);
            int Height = (int)(bottomRight.Y - topLeft.Y);

            using (Bitmap bmpScreenCapture = new Bitmap(Width,
                                                        Height))
            {
                using (System.Drawing.Graphics g = Graphics.FromImage(bmpScreenCapture))
                {
                    g.CopyFromScreen((int)(topLeft.X),
                                     (int)(topLeft.Y),
                                     0, 0,
                                     bmpScreenCapture.Size,
                                     CopyPixelOperation.SourceCopy);

                    // Write out the bitmap here encoded by a time-stamp?
                    String fname = output_root + DateTime.Now.ToString("yyyy-MMM-dd--HH-mm-ss") + ".png";
                    bmpScreenCapture.Save(fname, ImageFormat.Png);
                }
            }
        }
Пример #18
0
        public void CaptureScreen(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.F7)
            {
                return;
            }

            Point     CropA     = new Point(0, 0);
            Point     CropB     = new Point(0, 0);
            Rectangle firstcrop = new Rectangle(0, 0, 1, 1);

            Bitmap BMP = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
            GFX.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size, System.Drawing.CopyPixelOperation.SourceCopy);
            DataContainer.img1  = BMP;
            DataContainer.imgwi = BMP.Width;
            Point MousePos = System.Windows.Forms.Control.MousePosition;

            double imagerapport = (Convert.ToDouble(BMP.Width) / BMP.Height);

            //int lolppp = Convert.ToInt32(Math.Floor(imagerapport));

            if (imagerapport < 1.6)
            {
                DataContainer.screensize = 1;
            }                                                         // 4/3
            else if (imagerapport == 1.6)
            {
                DataContainer.screensize = 2;
            }                                                                //16/10
            else if (imagerapport > 1.6)
            {
                DataContainer.screensize = 3;
            }                                                               //16/9
            //richTextBox3.AppendText("\ng :"+ imagerapport.ToString());

            if (MousePos.X < (DataContainer.img1.Width / 2))
            {
                CropA.X = MousePos.X - 10;
                CropB.X = MousePos.X + Convert.ToInt32(DataContainer.img1.Width * 24.45 / 100) + 140;
            }
            else
            {
                CropA.X = MousePos.X - Convert.ToInt32(DataContainer.img1.Width * 24.45 / 100) - 140;
                CropB.X = MousePos.X + 10;
            }
            //CropX.X = MousePos.X - Convert.ToInt32(DataContainer.img1.Width * 24.45 / 100);
            //richTextBox3.AppendText(CropA.X.ToString() +";"+CropB.X.ToString() +"\n");

            //if ((MousePos.Y + 500) < DataContainer.img1.Height) { firstcrop = new Rectangle(CropA.X, 0, Math.Abs(CropA.X - CropB.X), (MousePos.Y + 500)); }
            firstcrop = new Rectangle(CropA.X, 0, Math.Abs(CropA.X - CropB.X), DataContainer.img1.Height);
            Bitmap firstc = cropImage(DataContainer.img1, firstcrop);

            firstc            = FindHeight(firstc);
            firstc            = FindWidth(firstc);
            pictureBox1.Image = firstc;
            //firstc.Save(@Application.StartupPath + "\\" + DateTime.Now.ToString().Replace(':','.') + ".jpeg", ImageFormat.Jpeg);
        }
Пример #19
0
 /// <summary>
 /// 获取窗口范围内的图像(Bitmap)
 /// </summary>
 /// <returns>图像Bitmap</returns>
 private System.Drawing.Bitmap GetWindowBitmap()
 {
     System.Drawing.Bitmap   bit = new System.Drawing.Bitmap((int)window.Width - 20, (int)window.Height - 60);
     System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(bit);
     g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
     g.CopyFromScreen((int)window.Left + 10, (int)window.Top + 25, (int)0, (int)0, new System.Drawing.Size((int)window.Width, (int)window.Height));
     return(bit);
 }
Пример #20
0
        /// <summary>
        /// Take a piece of the screen.
        /// </summary>
        /// <param name="source">The point indicated by the mouse.</param>
        /// <param name="size">The size of the area to be picked up.</param>
        /// <returns></returns>
        public static Bitmap TakeSnapshot(Point source, Size size)
        {
            Bitmap bmp = new Bitmap(size.Width, size.Height);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.CopyFromScreen(new Point(source.X - size.Width, source.Y - size.Height), new Point(0, 0), size);
            return(bmp);
        }
Пример #21
0
 System.Drawing.Bitmap GetScreen(Rectangle r)
 {
     System.Drawing.Bitmap   objBitmap   = new System.Drawing.Bitmap(r.Right - r.Left, r.Size.Height);
     System.Drawing.Graphics objGraphics = null;
     objGraphics = System.Drawing.Graphics.FromImage(objBitmap);
     objGraphics.CopyFromScreen(r.Location, new Point(0, 0), r.Size);
     return(objBitmap);
 }
Пример #22
0
        private static Bitmap TakeSnapshot(Rectangle targetRectangle)
        {
            Bitmap bmp = new Bitmap(targetRectangle.Width, targetRectangle.Height);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.CopyFromScreen(targetRectangle.Left, targetRectangle.Top, 0, 0, bmp.Size);
            return(bmp);
        }
    public string PixelGetColor(int x, int y)
    {
        Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(bmp);
        GFX.CopyFromScreen(x, y, 0, 0, new Size(1, 1), System.Drawing.CopyPixelOperation.SourceCopy);
        return(bmp.GetPixel(0, 0).ToArgb().ToString("X8").Substring(2, 6));
    }
Пример #24
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
     gr = Graphics.FromImage(bmp);
     gr.CopyFromScreen(0, 0, 0, 0,new Size(bmp.Width, bmp.Height));
     pictureBox1.Image = bmp;
     pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
 }
Пример #25
0
    Bitmap GetFormPic()
    {
        Size   ScreenSize = this.Size;
        Bitmap screenGrab = new Bitmap(this.Width, this.Height);

        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(screenGrab);
        g.CopyFromScreen(this.Location, new Point(0, 0), this.Size);
        return(screenGrab);
    }
    public int PixelGetColor(int x, int y, bool bRetInt)
    {
        Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(bmp);
        GFX.CopyFromScreen(x, y, 0, 0, new Size(1, 1), System.Drawing.CopyPixelOperation.SourceCopy);
        return(Int32.Parse(bmp.GetPixel(0, 0).ToArgb().ToString("X8").Substring(2, 6),
                           System.Globalization.NumberStyles.AllowHexSpecifier));
    }
Пример #27
0
        public static Bitmap CaptureScreen()
        {
            Bitmap BMP = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
            GFX.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0,
                               System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size, System.Drawing.CopyPixelOperation.SourceCopy);
            return(BMP);
        }
Пример #28
0
        public static System.Drawing.Bitmap TakeScreenshot()
        {
            System.Drawing.Bitmap screenshot = new System.Drawing.Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(screenshot);
            graphic.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
            graphic.Dispose();
            return(screenshot);
        }
Пример #29
0
        private Bitmap Screen()
        {
            Bitmap bitmap = new Bitmap(rect.width, rect.height);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);

            graphics.CopyFromScreen(rect.x, rect.y, 0, 0, bitmap.Size);

            return(bitmap);
        }
Пример #30
0
        D.Color GetColorAt(int x, int y)
        {
            D.Rectangle bounds = new D.Rectangle(x - 8, y - 8, 16, 16);

            using (D.Graphics gdest = D.Graphics.FromImage(bmp))
            {
                gdest.CopyFromScreen(bounds.Location, D.Point.Empty, bounds.Size);
            }
            return(bmp.GetPixel(7, 7));
        }
Пример #31
0
        public static Color ColorAtPixel(Point aPos)
        {
            Bitmap bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
            graphics.CopyFromScreen(aPos.X, aPos.Y, 0, 0, new Size(1, 1));
            Color ret = bitmap.GetPixel(0, 0);

            return(ret);
        }
        /// <summary>
        /// Draws the control to bitmap.
        /// (https://www.youtube.com/watch?v=x-tMlZ3LTw8)
        /// </summary>
        /// <param name="targetControl">The target control.</param>
        /// <returns></returns>
        public static Bitmap DrawControlToBitmap(Control targetControl)
        {
            Bitmap tempBitmap = new Bitmap(targetControl.Width, targetControl.Height);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(tempBitmap);

            Rectangle rect = targetControl.RectangleToScreen(targetControl.ClientRectangle);

            graphics.CopyFromScreen(rect.Location, Point.Empty, targetControl.Size);

            return(tempBitmap);
        }
Пример #33
0
        private void CaptureScreenArea(Graphics g, Point srcPos, Point destPos, Size area)
        {
            try
            {
                //lock (ScreenSnap)
                    g.CopyFromScreen(srcPos.X, srcPos.Y, destPos.X, destPos.Y, area, CopyPixelOperation.SourceCopy);

            }
            catch (Exception e)
            {

            }
        }
Пример #34
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Screenshot
            this.Hide();
            // Deixa o bitmap do tamanho da tela
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
            // Cria o objeto a partir do bitmap
            gfxScreenshot = Graphics.FromImage(bmpScreenshot);
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
            // Salva a screen
            bmpScreenshot.Save("C:\\Users\\gubat_000\\Documents\\Visual Studio 2013\\Projects\\TesteBrowser\\TesteBrowser\\bin\\Debug\\teste.png", ImageFormat.Png);

            this.Show();
            label1.Text = color;
        }
Пример #35
0
        public void CaptureVideo()
        {
            b = new Bitmap(ScreenWidth, ScreenHeight);
            g = Graphics.FromImage(b);
            g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);

            //auto set options for video recording
            //(description for each option availible at http://msdn.microsoft.com/en-us/library/windows/desktop/dd756832(v=vs.85).aspx)
            Avi.AVICOMPRESSOPTIONS aviOptions = new Avi.AVICOMPRESSOPTIONS();
            aviOptions.fccType = (uint)Avi.streamtypeVIDEO;
            //codec to use MSVC = Microsoft Video 1
            aviOptions.fccHandler = (uint)Avi.mmioStringToFOURCC("MSVC", 0);
            //quality option go from 0-10000
            aviOptions.dwQuality = 5000;

            //change aviOptions to "true" to enable the popup window asking for codec options eg. aviStream = aviManager.AddVideoStream(true, 4, b);
            aviStream = aviManager.AddVideoStream(aviOptions, 4, b);

            Bitmap tempBmp;

            while (!pause)
            {
                tempBmp = new Bitmap(ScreenWidth, ScreenHeight);
                g = Graphics.FromImage(tempBmp);
                g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
                g.FillEllipse(fillBrush, currentPoint.X, currentPoint.Y, 10, 10);
                g.FillRectangle(new SolidBrush(Color.Black), ScreenWidth - 100, ScreenHeight - 30, 100, 30);
                g.DrawString(elapsedTime, new Font("Arial", 12), new SolidBrush(Color.White), new PointF(ScreenWidth-95, ScreenHeight-25));

                if (tempBmp != null)
                {
                    try
                    {
                        aviStream.AddFrame(tempBmp);
                    }
                    catch
                    {
                        Bitmap bmp2 = tempBmp;
                        tempBmp.Dispose();
                        tempBmp = new Bitmap((Image)bmp2);
                        aviStream.AddFrame(tempBmp);
                    }
                }
                tempBmp.Dispose();
                Thread.Sleep(50);
            }
            aviManager.Close();
        }
Пример #36
0
        public Graph(PictureBox picture)
        {
            rnd = new Random();
            col = Color.FromArgb(rnd.Next(20, 255), rnd.Next(20, 255), rnd.Next(20, 255));
            this.picture = picture;
            bmp = new Bitmap(picture.Width, picture.Height);
            bmpN = new Bitmap(picture.Width, picture.Height);
            fullsize = Screen.PrimaryScreen.Bounds;

            graph = Graphics.FromImage(bmp);
            graphN = Graphics.FromImage(bmpN);
            graph.CopyFromScreen(fullsize.Left, fullsize.Top, 0, 0, fullsize.Size);
            graphN.CopyFromScreen(fullsize.Left, fullsize.Top, 0, 0, fullsize.Size);
            // graph.Clear(Color.White);
            penForge = new Pen(col, 2.0f);
            PenBack = new Pen(Color.White, 2.0f);
        }
Пример #37
0
 private void ClientBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     if (Directory.Exists(path))
     {
         while (true)
         {
             if (_performCapturing)
             {
                 bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                 gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                 gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                 
                 switch (i) 
                 {
                     case 0:
                     case 1:
                     case 2:
                     case 3:
                     case 4:
                     case 5:
                     case 6:
                     case 7:
                     case 8:
                     case 9:
                         bmpScreenshot.Save(path + "0" + i + ".png");
                         ClientService.SendFile(path +"0" + i + ".png");
                         break;
                     default:
                         bmpScreenshot.Save(path + i + ".png");
                         ClientService.SendFile(path + i + ".png");
                         break;
                 }
                 //ClientService.DeleteFile( i);
                 i++;
             }
         }
     }
 }
Пример #38
0
        /// <summary>
        /// Take a screen shot and save it to folder with group
        /// </summary>
        /// <param name="folder">Path for saving screen shot PNG</param>
        /// <param name="group">Group name if multiple computers save a screenshot</param>
        public void ScreenShot(string folder, string group)
        {
            string path = "";
            DateTime d = DateTime.Now;
            string strDate = d.ToString("yyyyMMddHHmmss");
            if (group.Length == 0)
            {
                group = "0";
            }
            if (folder.Length == 0)
            {
                path = @"c:\home\" + SystemInformation.ComputerName.ToString() + "-" + group + "-" + strDate + ".png";
            }
            else
            {
                if (folder.LastIndexOf(@"\") == folder.Length - 1)
                {
                    path = folder + SystemInformation.ComputerName.ToString() + "-" + group + "-" + strDate + ".png";
                }
                else
                {
                    path = folder + @"\" + SystemInformation.ComputerName.ToString() + "-" + group + "-" + strDate + ".png";
                }
            }

            try
            {
                // Set the bitmap object to the size of the screen
                bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

                // Create a graphics object from the bitmap
                gfxScreenshot = Graphics.FromImage(bmpScreenshot);

                // Take the screenshot from the upper left corner to the right bottom corner
                gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

                // Save the screenshot to the specified path that the user has chosen
                bmpScreenshot.Save(path, ImageFormat.Png);
            }
            catch
            {
                // Just swallow errors
            }
        }
Пример #39
0
        private void Timer1Tick(object sender, EventArgs e)
        {
            // Get the color from mouse (Y, X)
            _cursor = Cursor.Position;
            _graphic = Graphics.FromImage(_bmp);
            _graphic.CopyFromScreen(_point, _point, _bmp.Size);
            _color = _bmp.GetPixel(_cursor.X, _cursor.Y);

            UpdateColorData(_color);
        }
Пример #40
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if(!pauseoverride) pause = Convert.ToBoolean(Convert.ToInt32(Core.Settings.IniReadValue("ScreenCapture", "freeze")));
            imgur = Convert.ToBoolean(Convert.ToInt32(Core.Settings.IniReadValue("ScreenCapture", "imgur")));

            //WARNING: this code was written while I was drunk!!!!!!!!!
            //edit: and has been rewritten numerous times since then
            /*Out.WriteLine("---- MONITORS ----");
            Out.WriteDebug("Using X:0 Y:0 as default location");
            Rectangle primary = Screen.PrimaryScreen.Bounds;
            */
            /*Screen.

            foreach (Screen screen in Screen.AllScreens)
            {
                if(!screen.Primary)
                    primary.Inflate(screen.Bounds.Width, 0);
            }

            Location = new Point(0, 0);
            Size = new Size(w, h);

            Out.WriteLine("---- Calculation result ----");
            Out.WriteLine(Size.ToString());
            Out.WriteLine(Location.ToString());
            Out.WriteLine("----------------------------");*/

            var rect = SystemInformation.VirtualScreen;
            Size = new Size(rect.Width, rect.Height);
            Location = new Point(rect.Left, rect.Top);

            if (pause)
            {

                Out.WriteLine("NOW FREEEEZEEEEEE");
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(this.Width, this.Height);
                gfxScreenshot = Graphics.FromImage(bmp);
                Opacity = 0.0;
                gfxScreenshot.CopyFromScreen(0, 0, 0, 0, this.Size, CopyPixelOperation.SourceCopy);
                panel1.Hide();
                this.BackgroundImage = bmp;

                Cursor = Cursors.WaitCursor;

                timer1.Start();
            }
        }
        private void BwDoWork(object sender, DoWorkEventArgs e)
        {
            //to allow the report to load fully
            Thread.Sleep(1500);
            var form = this.Bounds;

            if (_first)
            {
                //print to a bmp and save file
                var panel = flowLayoutPanel1.Bounds;
                _bitmap = new Bitmap(panel.Width, panel.Height);
                _graphic = Graphics.FromImage(_bitmap);
                _graphic.CopyFromScreen(form.Location, Point.Empty, form.Size);
            }
            else
            {
                _graphic.CopyFromScreen(form.Location, new Point(0, this.VerticalScroll.Value - _initScroll), form.Size);

                //last only
                if (!_second)
                {
                    var pathPdf = "G:\\RoopeshCrap\\IndiaGovernsReports\\" + this._reportName + ".pdf";
                    saveAsPdf(_bitmap, pathPdf);
                }
            }
        }
Пример #42
0
        /// <summary>
        /// Capture the specified area of the screen
        /// </summary>
        /// <param name="Width">Width of area to capture</param>
        /// <param name="Height">Height of area to capture</param>
        /// <param name="xOffset">X-coordinate of screen offset</param>
        /// <param name="yOffset">Y-coordinate of screen offset</param>
        private void CaptureArea(int Width, int Height, int xOffset, int yOffset)
        {
            img = new Bitmap(Width, Height);
            gfx = Graphics.FromImage(img);
            gfx.CopyFromScreen(xOffset, yOffset, 0, 0, new Size(Width, Height), CopyPixelOperation.SourceCopy);

            SaveImage();
        }
        void our_Server()
        {
            try
            {
                mytcpl = new TcpListener(23);
                mytcpl.Start();
                mysocket = mytcpl.AcceptSocket();
                myns = new NetworkStream(mysocket);
                byte[] buffer = new byte[1024];
                myns.Read(buffer, 0, 1024);
                MemoryStream ms = new MemoryStream(buffer);

                DateTime dt = DateTime.Now;

                string s = new StreamReader(ms).ReadToEnd();

                if (s.IndexOf("<Message>") == 0)
                {
                    s = s.Replace("<Message>","");
                    Match m_caption = Regex.Match(s, "<StartCaption>.*<EndCaption>", RegexOptions.Singleline);
                    Match m_text = Regex.Match(s, "<StartText>.*<EndText>", RegexOptions.Singleline);
                    string s_caption = m_caption.ToString().Replace("<StartCaption>", "").Replace("<EndCaption>", "");
                    string s_text = m_text.ToString().Replace("<StartText>", "").Replace("<EndText>", "");

                    string str = dt + " " + host + " (" + ip.ToString() + ") message (" + s_caption + ", " + s_text + ") sent ok";

                    sent_report(str);

                    MessageBox.Show(s_text, s_caption);

                }

                if (s.IndexOf("<Update>") == 0)
                {
                    string str = dt + " " + host + " (" + ip.ToString() + ") update ok";
                    sent_report(str);
                    Process process_run_program = new Process();
                    process_run_program.StartInfo.FileName = Application.StartupPath + @"\update.exe";
                    process_run_program.Start();
                    this.Close();
                }

                if (s.IndexOf("<PrimaryInternet>") == 0)
                {
                    SetGateway("192.168.8.234");
                    string str = dt + " " + host + " (" + ip.ToString() + ") Gateway Primary Internet Update";
                    sent_report(str);
                }

                if (s.IndexOf("<ReserveInternet>") == 0)
                {
                    SetGateway("192.168.8.230");
                    string str = dt + " " + host + " (" + ip.ToString() + ") Gateway Reserve Internet Update";
                    sent_report(str);
                }

                if (s.IndexOf("<Check>") == 0)
                {
                    string str = dt + " " + host + " (" + ip.ToString() + ") version " + fvi.FileVersion + " on-line";
                    sent_report(str);
                }

                if (s.IndexOf("<Screen>") == 0)
                {
                    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                    // Create a graphics object from the bitmap

                    gfxScreenshot = Graphics.FromImage(bmpScreenshot);

                    // Take the screenshot from the upper left corner to the right bottom corner

                    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

                    // Save the screenshot to the specified path that the user has chosen

                    bmpScreenshot.Save("screen\\" + dt.ToString("HHmmss_ddMMyyyy") + ".png", ImageFormat.Png);

                    // Show the form again

                    string str = dt + " " + host + " (" + ip.ToString() + ") screenshot ok";
                    sent_report(str);
                }

                mytcpl.Stop();

                if (mysocket.Connected == true)
                {
                    while (true)
                    {
                        our_Server();
                    }
                }
            }
            catch (Exception)
            {

            }
        }
        private void PlaybackIndicatorInvert(Graphics g, int elapsedUS)
        {
            //get the upper left corner of the start of the invert operation
            Point PPOrigin = Point.Round(new PointF(TimeToX(elapsedUS), 0));

            if (!g.Clip.IsVisible(PPOrigin, g))  //dont bother inverting outside of the graphics clip region
                return; //this is important for partial re-paint events

            g.CopyFromScreen(   //do the invert operation
                PPOrigin,
                PPOrigin,
                new Size(4, PanelProgress.Height),
                CopyPixelOperation.DestinationInvert);
        }
Пример #45
0
        private void Screenshot_MouseUp(object sender, MouseEventArgs e)
        {
            if (LeftButtonDown)
            {
                LeftButtonDown = false;
                DestinationPoint = new Point(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y);

                //Conceal this form while the screen capture takes place
                this.Hide();

                //Allow 250 milliseconds for the screen to repaint itself
                System.Threading.Thread.Sleep(250);

                int height = 0;
                int width = 0;

                if (SourcePoint.X < DestinationPoint.X && SourcePoint.Y < DestinationPoint.Y)
                {
                    width = DestinationPoint.X - SourcePoint.X;
                    height = DestinationPoint.Y - SourcePoint.Y;
                }
                else if (SourcePoint.X >= DestinationPoint.X && SourcePoint.Y >= DestinationPoint.Y)
                {
                    width = SourcePoint.X - DestinationPoint.X;
                    height = SourcePoint.Y - DestinationPoint.Y;
                }
                else
                {
                    //ScreenFail
                    height = 50;
                    width = 50;
                }

                // Set the bitmap object to the size of the screen
                bmpScreenshot = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                //bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

                // Create a graphics object from the bitmap
                gfxScreenshot = Graphics.FromImage(bmpScreenshot);

                Size screen = new Size(width, height);

                // Take the screenshot from the upper left corner to the right bottom corner
                if (SourcePoint.X < DestinationPoint.X && SourcePoint.Y < DestinationPoint.Y)
                {
                    gfxScreenshot.CopyFromScreen(SourcePoint.X, SourcePoint.Y, 0, 0, screen, CopyPixelOperation.SourceCopy);
                }
                else
                {
                    gfxScreenshot.CopyFromScreen(DestinationPoint.X, DestinationPoint.Y, 0, 0, screen, CopyPixelOperation.SourceCopy);
                }

                theimage.Image = bmpScreenshot;
                this.Close();
            }
        }
Пример #46
0
 public void saveFrame(string path)
 {
     this.Show();
     bmpScreenshot = new Bitmap(getWindowDimensions()[0], getWindowDimensions()[1], System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     gfxScreenshot = Graphics.FromImage(bmpScreenshot);
     SetForegroundWindow(this.Handle);
     Thread.Sleep(100);//not sure if needed
     gfxScreenshot.CopyFromScreen(getWindowLocation()[0], getWindowLocation()[1], 0, 0, new Size(getWindowDimensions()[0], getWindowDimensions()[1]), CopyPixelOperation.SourceCopy);
     bmpScreenshot.Save(path, ImageFormat.Jpeg);
     log("saved: " + path);
 }
Пример #47
0
 private void copyBackground(Graphics g)
 {
     RECT windowRect = new RECT();
     GetWindowRect(_hTipWnd, ref windowRect);
     g.CopyFromScreen(windowRect.Left, windowRect.Top, 0, 0, new Size(windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top), CopyPixelOperation.SourceCopy);
 }
Пример #48
0
        private void ScreenFull()
        {
            //Conceal this form while the screen capture takes place
            this.Hide();

            //Allow 250 milliseconds for the screen to repaint itself
            System.Threading.Thread.Sleep(250);

            // Set the bitmap object to the size of the screen
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap
            gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            picSave.Image = bmpScreenshot;

            picSave.Enabled = true;
            btnPreview.Enabled = true;
            btnUpload.Enabled = true;
            btnCancel.Enabled = true;

            //Show Form Again
            this.Show();
            this.WindowState = FormWindowState.Normal;

            tabControl1.SelectedTab = tabPage6;
        }
Пример #49
0
        private void DeskCapture()
        {
            int redL = 0, greenL = 0, blueL = 0;
            int redR = 0, greenR = 0, blueR = 0;
            int redT = 0, greenT = 0, blueT = 0;
            int CounterL = 0, CounterR = 0, CounterT = 0;
            bool read = false;
            bool CaptureScreen = false;

            Color c = Color.Black;

            Screen MyScreen = Screen.AllScreens[GlobalVariables.SelectedDisplay];

            if ((CaptureEvery.Checked == false) || (CaptureEvery.Checked == true && CyclesInt == 0))
            {
                CaptureScreen = true;
            }

            if (CaptureEvery.Checked == true)
            {
                CyclesInt = CyclesInt + 1;
            }

            if (CaptureScreen == true)
            {
                b = new Bitmap(MyScreen.Bounds.Width, MyScreen.Bounds.Height);
                g = Graphics.FromImage(b);
                g.CopyFromScreen(MyScreen.Bounds.Left, MyScreen.Bounds.Top, 0, 0, new Size(MyScreen.Bounds.Width, MyScreen.Bounds.Height));
            }

            // b.Save("temp.jpg", ImageFormat.Jpeg);

            swidth = b.Width;
            sheight = b.Height;

            // b.Save("temp.jpg", ImageFormat.Jpeg);

            int divide = (int)DivideLevel.Value;
            GlobalVariables.Offset = (int)OffsetLevel.Value;
            if (GlobalVariables.mode == 1)
            {
                divide = 32;
                GlobalVariables.Offset = 0;
            }

            int dx = swidth / divide;
            int dy = sheight / divide;

            int offsetx = dx / 3 * GlobalVariables.Offset;
            int offsety = dy / 3 * GlobalVariables.Offset;

            if (this.WindowState != FormWindowState.Minimized)
            {
                label36.Text = MyScreen.Bounds.Width + "x" + MyScreen.Bounds.Height + " (" + MyScreen.Bounds.Left + ", " + MyScreen.Bounds.Top + ")";

                label60.Text = dx.ToString();
                label62.Text = dy.ToString();

                label66.Text = swidth.ToString();
                label69.Text = sheight.ToString();

                label64.Text = "~" + divide.ToString();
                label65.Text = "~" + divide.ToString();

                label74.Text = offsetx.ToString();
                label72.Text = offsety.ToString();
            }

            for (int PixelY = offsety; PixelY < sheight; PixelY += dy)
                {
                for (int PixelX = offsetx; PixelX < swidth; PixelX += swidth / divide)
                {

                    {
                        read = false;

                        if (PixelX >= swidth * LeftBegin.Value / 100 && PixelX <= swidth * LeftEnd.Value / 100)
                        {
                            if (read == false)
                            {
                                c = b.GetPixel(PixelX, PixelY);
                                read = true;
                            }
                            redL += c.R;
                            greenL += c.G;
                            blueL += c.B;
                            CounterL++;
                        }
                        if (PixelX >= swidth * RightBegin.Value / 100 && PixelX <= swidth * RightEnd.Value / 100)
                        {
                            if (read == false)
                            {
                                c = b.GetPixel(PixelX, PixelY);
                                read = true;
                            }
                            redR += c.R;
                            greenR += c.G;
                            blueR += c.B;
                            CounterR++;
                        }
                        if (PixelY >= sheight * TopBegin.Value / 100 && PixelY <= sheight * TopEnd.Value / 100)
                        {
                            if (read == false)
                            {
                                c = b.GetPixel(PixelX, PixelY);
                                read = true;
                            }
                            redT += c.R;
                            greenT += c.G;
                            blueT += c.B;
                            CounterT++;
                        }

                    }
                }
            }

            if (CounterL > 0)
            {
                redL /= CounterL;
                greenL /= CounterL;
                blueL /= CounterL;
            }
            if (CounterR > 0)
            {
                redR /= CounterR;
                greenR /= CounterR;
                blueR /= CounterR;
            }
            if (CounterT > 0)
            {
                redT /= CounterT;
                greenT /= CounterT;
                blueT /= CounterT;
            }
            if (redL > 0 || greenL > 0 || blueL > 0 || redR > 0 || greenR > 0 || blueR > 0 || redT > 0 || greenT > 0 || blueT > 0 || GlobalVariables.blackframe)
            {
                GlobalVariables.blackframe = false;
                Array.Copy(GlobalVariables.PreviousColor29, GlobalVariables.PreviousColor30, 9);
                Array.Copy(GlobalVariables.PreviousColor28, GlobalVariables.PreviousColor29, 9);
                Array.Copy(GlobalVariables.PreviousColor27, GlobalVariables.PreviousColor28, 9);
                Array.Copy(GlobalVariables.PreviousColor26, GlobalVariables.PreviousColor27, 9);
                Array.Copy(GlobalVariables.PreviousColor25, GlobalVariables.PreviousColor26, 9);
                Array.Copy(GlobalVariables.PreviousColor24, GlobalVariables.PreviousColor25, 9);
                Array.Copy(GlobalVariables.PreviousColor23, GlobalVariables.PreviousColor24, 9);
                Array.Copy(GlobalVariables.PreviousColor22, GlobalVariables.PreviousColor23, 9);
                Array.Copy(GlobalVariables.PreviousColor21, GlobalVariables.PreviousColor22, 9);
                Array.Copy(GlobalVariables.PreviousColor20, GlobalVariables.PreviousColor21, 9);
                Array.Copy(GlobalVariables.PreviousColor19, GlobalVariables.PreviousColor20, 9);
                Array.Copy(GlobalVariables.PreviousColor18, GlobalVariables.PreviousColor19, 9);
                Array.Copy(GlobalVariables.PreviousColor17, GlobalVariables.PreviousColor18, 9);
                Array.Copy(GlobalVariables.PreviousColor16, GlobalVariables.PreviousColor17, 9);
                Array.Copy(GlobalVariables.PreviousColor15, GlobalVariables.PreviousColor16, 9);
                Array.Copy(GlobalVariables.PreviousColor14, GlobalVariables.PreviousColor15, 9);
                Array.Copy(GlobalVariables.PreviousColor13, GlobalVariables.PreviousColor14, 9);
                Array.Copy(GlobalVariables.PreviousColor12, GlobalVariables.PreviousColor13, 9);
                Array.Copy(GlobalVariables.PreviousColor11, GlobalVariables.PreviousColor12, 9);
                Array.Copy(GlobalVariables.PreviousColor10, GlobalVariables.PreviousColor11, 9);
                Array.Copy(GlobalVariables.PreviousColor9, GlobalVariables.PreviousColor10, 9);
                Array.Copy(GlobalVariables.PreviousColor8, GlobalVariables.PreviousColor9, 9);
                Array.Copy(GlobalVariables.PreviousColor7, GlobalVariables.PreviousColor8, 9);
                Array.Copy(GlobalVariables.PreviousColor6, GlobalVariables.PreviousColor7, 9);
                Array.Copy(GlobalVariables.PreviousColor5, GlobalVariables.PreviousColor6, 9);
                Array.Copy(GlobalVariables.PreviousColor4, GlobalVariables.PreviousColor5, 9);
                Array.Copy(GlobalVariables.PreviousColor3, GlobalVariables.PreviousColor4, 9);
                Array.Copy(GlobalVariables.PreviousColor2, GlobalVariables.PreviousColor3, 9);
                Array.Copy(GlobalVariables.PreviousColor, GlobalVariables.PreviousColor2, 9);
                Array.Copy(GlobalVariables.CurrentColor, GlobalVariables.PreviousColor, 9);

                GlobalVariables.CurrentColor[0] = redL;
                GlobalVariables.CurrentColor[3] = greenL;
                GlobalVariables.CurrentColor[6] = blueL;
                GlobalVariables.CurrentColor[2] = redR;
                GlobalVariables.CurrentColor[5] = greenR;
                GlobalVariables.CurrentColor[8] = blueR;
                GlobalVariables.CurrentColor[1] = redT;
                GlobalVariables.CurrentColor[4] = greenT;
                GlobalVariables.CurrentColor[7] = blueT;

                //if (checkBox1.Checked)
                if (radioButton2.Checked)
                {
                    int[] Highest = new int[3] { 0, 0, 0 };
                    for (int I = 0; I < 9; I += 3)
                    {
                        if (Highest[0] < GlobalVariables.CurrentColor[I]) Highest[0] = GlobalVariables.CurrentColor[I];
                        if (Highest[1] < GlobalVariables.CurrentColor[I + 1]) Highest[1] = GlobalVariables.CurrentColor[I + 1];
                        if (Highest[2] < GlobalVariables.CurrentColor[I + 2]) Highest[2] = GlobalVariables.CurrentColor[I + 2];
                    }
                    float[] Multiply = new float[3];
                    for (int I = 0; I < 3; I++)
                    {
                        Multiply[I] = 255.0F / (float)Highest[I];
                        if (Multiply[I] > (float)numericUpDown1.Value) Multiply[I] = (float)numericUpDown1.Value;
                    }
                    for (int I = 0; I < 9; I += 3)
                    {
                        GlobalVariables.CurrentColor[I] = (int)((float)GlobalVariables.CurrentColor[I] * Multiply[0]);
                        GlobalVariables.CurrentColor[I + 1] = (int)((float)GlobalVariables.CurrentColor[I + 1] * Multiply[1]);
                        GlobalVariables.CurrentColor[I + 2] = (int)((float)GlobalVariables.CurrentColor[I + 2] * Multiply[2]);
                    }
                }

                if (radioButton3.Checked)
                {
                    int Highest = 0;
                    for (int I = 0; I < 9; I++)
                    {
                        if (Highest < GlobalVariables.CurrentColor[I])
                            Highest = GlobalVariables.CurrentColor[I];
                    }
                    float Multiply = 255.0F / (float)Highest;
                    if (Multiply > (float)numericUpDown1.Value)
                    {
                        Multiply = (float)numericUpDown1.Value;
                    }
                    for (int I = 0; I < 9; I++)
                    {
                        GlobalVariables.CurrentColor[I] = (int)((float)GlobalVariables.CurrentColor[I] * Multiply);
                    }
                }
                GlobalVariables.Offset++;
                if (GlobalVariables.Offset == 3)
                {
                    GlobalVariables.Offset = 0;
                }
            }
            else
            {
                GlobalVariables.blackframe = true;
            }

            if (CaptureScreen == true)
            {
            }

            if ((CyclesInt > CaptureCycles.Value) || (CaptureEvery.Checked == false))
            {
                CyclesInt = 0;
                g.Dispose();
                b.Dispose();
            }
        }
Пример #50
0
        /// <summary>
        /// Returns the average Color of the set CaptureScreen. Uses one
        /// of two methods to determine average color.
        /// </summary>
        /// <returns></returns>
        public Color AverageColor()
        {
            // Temporary variable for the found color.
            Color color;

            // Create an array to store the retrieved colors based on
            // selected Screen and Gridsize.
            var pixels = new Color[PixelAmount];

            // Capture the screen and store the required pixels in the array
            using (screen = new Bitmap(CaptureScreen.Bounds.Width, CaptureScreen.Bounds.Height)) {
                // Create a graphics object to capture the screen
                graphics = Graphics.FromImage(screen);
                graphics.CopyFromScreen(CaptureScreen.Bounds.X, CaptureScreen.Bounds.Y,
                    0, 0, CaptureScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

                // Fill the array with the required pixels
                int pixelcounter = 0;
                for (int x = Gridsize; x < CaptureScreen.Bounds.Width; x += Gridsize) {
                    for (int y = Gridsize; y < CaptureScreen.Bounds.Height; y += Gridsize) {
                        pixels[pixelcounter] = screen.GetPixel(x, y);
                        pixelcounter++;
                    }
                }

                // Tames the hungry, hungry RAM hippo
                screen.Dispose();
                graphics.Dispose();
            }

            // Determine average color based on selected CaptureMethod
            color = (Method == CaptureMethod.Ambuino) ? AverageAmbuino(pixels) : AverageRGB(pixels);

            // Apply smoothing if set
            if (Smoothing) {
                color = Color.FromArgb(
                    (color.R + lastcolor.R) / 2,
                    (color.G + lastcolor.G) / 2,
                    (color.B + lastcolor.B) / 2
                    );
                lastcolor = color;
            }

            return color;
        }
Пример #51
0
        /// <summary>
        /// Called when the overlay is redrawn
        /// </summary>
        /// <param name="g">Graphics g</param>
        public static void OnRender(Graphics g)
        {
            //Transparent background
            g.CopyFromScreen(MyOverlay.Boundings.Location, Point.Empty, MyOverlay.Boundings.Size, CopyPixelOperation.SourceCopy);

            // Background rectangle. Added RoundedCorner to height to hide the top corner.
            Rectangle background = new Rectangle(0, -RoundedCorner, MyOverlay.Size.Width - 2, MyOverlay.Size.Height- 2 + RoundedCorner);

            // abgerundetes Rechteck mit Farbverlauf zeichnen
            DrawRoundedRectangle(g, background, RoundedCorner, Color.Black, new SolidBrush(_colorBackground));

            //draw progressbar
            DrawProgressBar(g);

            //draw hotkeys
            DrawHotKeys(g);
        }
Пример #52
0
        /// <summary>
        /// Click events for top menu items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void topMenu_Click(object sender, EventArgs e)
        {
            Label lbl = sender as Label;
            switch (lbl.Text)
            {
                // when View is clicked, change attributes accordingly
                case "View":
                    lbl.BorderStyle = BorderStyle.Fixed3D;
                    imageMenu.BorderStyle = BorderStyle.None;
                    pnlViewMenu.Visible = true;
                    pnlImageMenu.Visible = false;
                    g = Graphics.FromImage(img);
                    break;
                // when Image is clicked, change attributes accordingly
                case "Image":
                    lbl.BorderStyle = BorderStyle.Fixed3D;
                    viewMenu.BorderStyle = BorderStyle.None;
                    pnlViewMenu.Visible = false;
                    pnlImageMenu.Visible = true;
                    imgSelect.BorderStyle = BorderStyle.None;
                    imgBrush.BorderStyle = BorderStyle.None;
                    imgPencil.BorderStyle = BorderStyle.None;
                    imgText.BorderStyle = BorderStyle.None;
                    imgLines.BorderStyle = BorderStyle.None;
                    break;
                // for entering text
                case "Submit":
                    if (tsStatusBar.Text == "Text")
                    {
                        g.DrawString(tbText.Text, tbText.Font, mainPen.Brush, pt1);
                        pbDraw.Image = img;
                    }
                    break;
                case "Clear":
                    // remove the image
                    if (pbDraw.Image != null)
                    {
                        pbDraw.Image.Dispose();
                        // reset the graphics and image
                        g = pbDraw.CreateGraphics();
                        img = new Bitmap(pbDraw.Width, pbDraw.Height, g);
                        g = Graphics.FromImage(img);
                        // message indicating the mechanics
                        MessageBox.Show("Begin drawing and image will clear");
                    }
                    break;
                // save image to desired location
                case "Save":
                    // create new save file dialog
                    SaveFileDialog s = new SaveFileDialog();

                    // create a new bitmap of the drawing
                    Bitmap bmp = new Bitmap(pbDraw.Width, pbDraw.Height);
                    g = Graphics.FromImage(bmp);

                    // copy the image
                    Rectangle rect = pbDraw.RectangleToScreen(pbDraw.ClientRectangle);
                    g.CopyFromScreen(rect.Location, Point.Empty, pbDraw.Size);
                    g.Dispose();

                    // adding this saves a few lines, requires a namespace
                    ImageFormat format = ImageFormat.Png;
                    s.Filter = "Images|*.png; *.jpg; *.bmp";

                    // get the file extension
                    string extension = System.IO.Path.GetExtension(s.FileName);

                    // check if save dialog opened
                    if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        switch (extension)
                        {
                            case ".jpg":
                                format = ImageFormat.Jpeg;
                                break;
                            case ".bmp":
                                format = ImageFormat.Bmp;
                                break;
                        }
                        // save file to specified format
                        bmp.Save(s.FileName, format);
                    }
                    break;
                // when Color is clicked, display color dialog
                case "Color":
                    colorDialog.ShowDialog();
                    break;
            }
        }
Пример #53
0
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            desktopBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            using (graphicsFromDesktop = Graphics.FromImage(desktopBitmap))
            {
                graphicsFromDesktop.CopyFromScreen(Screen.PrimaryScreen.Bounds.Location, new Point(0,0), Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
            }

            if (pictureBox1.Image != null)
                pictureBox1.Image.Dispose();

            pictureBox1.Image = desktopBitmap;
        }
Пример #54
0
 private void capture()
 {
     printscreen = new Bitmap(intWidth, intHeight);
     gfx = Graphics.FromImage(printscreen as Image);
     gfx.CopyFromScreen(intTop, intleft, 0, 0, printscreen.Size);
 }
Пример #55
0
        private void Screenshot()
        {
            videoCaptureHeight = Screen.PrimaryScreen.Bounds.Height / config.height; //To update the capture portion.

            bmpScreenshot = new Bitmap(videoCaptureWidth, videoCaptureHeight); //Create new bitmap with appropriate size

            g = Graphics.FromImage(bmpScreenshot); //Create graphics from bitmap

            s = new Size(videoCaptureWidth, videoCaptureHeight); //Set the size of capture area

            g.CopyFromScreen(offsetFromLeft, config.offset, 0, 0, s); //Take picture of screen and put into graphics
        }
Пример #56
0
        /// <summary>
        /// 截取屏幕
        /// </summary>
        public static void DoClipScreen()
        {
            CatchScreen = new Form();
            CatchScreen.FormBorderStyle = FormBorderStyle.None;
            CatchScreen.BackColor = System.Drawing.Color.White;
            CatchScreen.TransparencyKey = System.Drawing.Color.White;
            CatchScreen.Width = Screen.AllScreens[0].Bounds.Width;
            CatchScreen.Height = Screen.AllScreens[0].Bounds.Height;
            CatchScreen.StartPosition = FormStartPosition.CenterScreen;
            screenImage = new Bitmap(screenWidth, screenHeight);
            g = Graphics.FromImage(screenImage);
            g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), new System.Drawing.Size(screenWidth, screenHeight));
            CatchScreen.BackgroundImage = screenImage;

            CatchScreen.MouseClick += new MouseEventHandler(delegate(object obj, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                        startPoint = new Point(0, 0);
                        endPoint = new Point(0, 0);
                        point = new Point(0, 0);
                        CatchScreen.BackgroundImage = screenImage;
                        return;
                }
                if (!startPoint.IsEmpty && !endPoint.IsEmpty)
                    return;
                if (startPoint.IsEmpty)
                {
                    point = startPoint = e.Location;
                    tmpScreenImage = screenImage.Clone() as Bitmap;
                    tmpG = Graphics.FromImage(tmpScreenImage);
                    tmpG.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    tmpG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    tmpG.FillRectangle(new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, color, color), 0, 0, screenWidth, screenHeight);
                    tmpG.FillEllipse(System.Drawing.Brushes.HotPink, startPoint.X - 2, startPoint.Y - 2, 5, 5);
                    tmpG.DrawString(string.Format("{0},{1}", startPoint.X, startPoint.Y), SystemFonts.DefaultFont, System.Drawing.Brushes.HotPink, startPoint.X - 50, startPoint.Y - 20);
                    CatchScreen.BackgroundImage = tmpScreenImage.Clone() as Image;
                    return;
                }
                endPoint = e.Location;

                //判断选区左上的点坐标
                if ((endPoint.X > startPoint.X && endPoint.Y < startPoint.Y) || (endPoint.X < startPoint.X && endPoint.Y > startPoint.Y))
                    point = new Point(startPoint.X < endPoint.X ? startPoint.X : endPoint.X, startPoint.Y < endPoint.Y ? startPoint.Y : endPoint.Y);
                else if ((startPoint.X == endPoint.X) && (startPoint.Y == endPoint.Y))
                {
                    startPoint = new Point(0, 0);
                    endPoint = new Point(0, 0);
                    point = new Point(0, 0);
                    CatchScreen.BackgroundImage = screenImage;
                    return;
                }
                else
                    point = startPoint.X < endPoint.X ? startPoint : endPoint;

                tmpG.FillEllipse(System.Drawing.Brushes.HotPink, endPoint.X - 2, endPoint.Y - 2, 5, 5);
                tmpG.DrawString(string.Format("{0},{1}", endPoint.X, endPoint.Y), SystemFonts.DefaultFont, System.Drawing.Brushes.HotPink, endPoint.X + 50, endPoint.Y + 20);

                //选区的border
                tmpG.DrawRectangle(System.Drawing.Pens.Pink, point.X, point.Y, clipWidth, clipHeight);

                tmpG.FillRectangle(new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, innerColor, innerColor), point.X, point.Y, clipWidth, clipHeight);

                CatchScreen.BackgroundImage = tmpScreenImage;
            });

            CatchScreen.MouseDoubleClick += new MouseEventHandler(delegate(object obj, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    startPoint = new Point(0, 0);
                    endPoint = new Point(0, 0);
                    point = new Point(0, 0);
                    CatchScreen.Close();
                    return;
                }
                if (startPoint.IsEmpty || endPoint.IsEmpty)
                    return;
                tmpScreenImage = new Bitmap(clipWidth, clipHeight);
                tmpG = Graphics.FromImage(tmpScreenImage);
                tmpG.DrawImage(screenImage, new System.Drawing.Rectangle(0, 0, clipWidth, clipHeight), new System.Drawing.Rectangle(point.X, point.Y, clipWidth, clipHeight), System.Drawing.GraphicsUnit.Pixel);
                ClipCompleteEvent(tmpScreenImage);
                CatchScreen.Close();
            });

            CatchScreen.KeyPress += new KeyPressEventHandler(delegate(object obj,KeyPressEventArgs e)
            {
                if (e.KeyChar == 27)
                {
                    startPoint = new Point(0, 0);
                    endPoint = new Point(0, 0);
                    point = new Point(0, 0);
                    CatchScreen.Close();
                }
            });

            CatchScreen.FormClosing += new FormClosingEventHandler(delegate(object obj, FormClosingEventArgs e)
            {
                if (tmpScreenImage != null)
                    tmpScreenImage.Dispose();
                if (tmpG != null)
                    tmpG.Dispose();
                if (screenImage != null)
                    screenImage.Dispose();
                if (g != null)
                    g.Dispose();
            });

            CatchScreen.Show();
            CatchScreen.Activate();
        }
Пример #57
0
        void hook_KeyPressed(object sender, KeyPressedEventArgs e)
        {
            // print full screen
            if (e.Key == fallyGrab.Properties.Settings.Default.keyShortcut)
            {
                // check if save folder exists
                try
                {
                    // get file name
                    string file = commonFunctions.fileName();
                    // set the bitmap object to the size of the screen
                    ImageCodecInfo myImageCodecInfo;
                    System.Drawing.Imaging.Encoder myEncoder;
                    EncoderParameter myEncoderParameter;
                    EncoderParameters myEncoderParameters;
                    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppRgb);
                    // create a graphics object from the bitmap
                    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                    // take the screenshot from the upper left corner to the right bottom corner
                    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                    // save the screenshot to the specified path that the user has chosen
                    if (fallyGrab.Properties.Settings.Default.imageFormat == "JPG")
                        myImageCodecInfo = GetEncoderInfo("image/jpeg");
                    else
                        myImageCodecInfo = GetEncoderInfo("image/png");

                     myEncoder = System.Drawing.Imaging.Encoder.Quality;
                     myEncoderParameters = new EncoderParameters(1);
                     myEncoderParameter = new EncoderParameter(myEncoder, Convert.ToInt64(fallyGrab.Properties.Settings.Default.quality));
                     myEncoderParameters.Param[0] = myEncoderParameter;
                     bmpScreenshot.Save(ssfolder + "\\fallyGrab-" + file, myImageCodecInfo, myEncoderParameters);

                    string urlReturned = "";
                    // facebook
                    if (fallyGrab.Properties.Settings.Default.uploadType == "Facebook")
                        uploadFacebook(ssfolder + "\\fallyGrab-" + file);
                    else
                        urlReturned = commonFunctions.useScreenshot(ssfolder + "\\fallyGrab-" + file,ssfolder);
                    // add link to history if returned
                    if (urlReturned != "")
                    {
                        writeHistory(urlReturned);
                    }

                }
                catch (Exception ex)
                {
                    fallyToast.Toaster alertformfolder = new fallyToast.Toaster();
                    alertformfolder.Show("fallyGrab", "Error: "+ex.Message, -1, "Fade", "Up","","","error");
                    commonFunctions.writeLog(ex.Message, ex.StackTrace);
                }
            }
            else if (e.Key == Properties.Settings.Default.keyShortcut2)
            {
                if (!isCropperOpen())
                {
                    cropperForm cropperForm = new cropperForm(this);
                    cropperForm.ssfolder = ssfolder;
                    cropperForm.ShowDialog();

                    // add to history
                    if (cropperForm.urlCrop != "")
                    {
                        string urlReturned = "";
                        // facebook
                        if (fallyGrab.Properties.Settings.Default.uploadType == "Facebook")
                            uploadFacebook(ssfolder + "\\fallyGrab-" + cropperForm.urlCrop);
                        else
                            urlReturned = commonFunctions.useScreenshot(ssfolder + "\\fallyGrab-" + cropperForm.urlCrop, ssfolder);
                        // add link to history if returned
                        if (urlReturned != "")
                        {
                            writeHistory(urlReturned);
                        }
                    }

                }
            }

            // garbage collector
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
Пример #58
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (down)
            {
                if (notrunnedyet)
                {
                    string temp = "";
                    try
                    {
                        notrunnedyet = false;
                        Opacity = 0.0;
                        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(this.Width, this.Height);
                        gfxScreenshot = Graphics.FromImage(bmp);
                        gfxScreenshot.CopyFromScreen((MousePosition.X - this.Size.Width), (MousePosition.Y - this.Size.Height), 0, 0, this.Size, CopyPixelOperation.SourceCopy);

                        temp = Core.UserDir + "\\" + Path.GetRandomFileName();
                        bmp.Save(temp, System.Drawing.Imaging.ImageFormat.Png);
                        LE_DERPDERP_FILE = temp;

                        if (!imgur)
                        {
                            wc = new WebClient();
                            wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
                            wc.UploadValuesCompleted += new UploadValuesCompletedEventHandler(wc_UploadValuesCompleted);
                            ThreadPool.QueueUserWorkItem(new WaitCallback(checkProgress));
                            NameValueCollection nvc = new NameValueCollection();
                            nvc.Add("type", "image");
                            nvc.Add("content", Convert.ToBase64String(File.ReadAllBytes(temp)));
                            string key = Core.Settings.IniReadValue("MISC", "userkey");
                            string ukey = "";
                            if (key != string.Empty)
                                ukey = "?userkey=" + Crypto.DecryptStringAES(key, Core.Secret);

                            wc.UploadValuesAsync(new Uri("http://upload.easycaptu.re/"+Application.ProductVersion+ukey), nvc);
                        }
                        else
                        {
                            wc = new WebClient();
                            wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
                            wc.UploadValuesCompleted += new UploadValuesCompletedEventHandler(wc_UploadValuesCompleted);
                            NameValueCollection values = new NameValueCollection();
                            values.Add("key", Core.ApiKeys.Imgur.DevKey);
                            values.Add("image", Convert.ToBase64String(File.ReadAllBytes(temp)));
                            values.Add("caption", "Uploaded with http://easycaptu.re/ - Capture media from your computer with just a keypress and share it instantly!");
                            string url = "http://api.imgur.com/2/upload";
                            ThreadPool.QueueUserWorkItem(new WaitCallback(checkProgress));
                            string key = Core.Settings.IniReadValue("ScreenCapture", "user_key");
                            if (key != string.Empty)
                            {
                                wc.Headers.Add("Cookie", Crypto.DecryptStringAES(key, Core.Secret));

                                /*OAuth.Manager oauth = new OAuth.Manager();
                                string[] s = key.Split(new string[] { "|" }, StringSplitOptions.None);
                                OAuthBase obase = new OAuthBase();
                                string nurl;
                                string nreq;
                                string sig = obase.GenerateSignature(new Uri("http://api.imgur.com/2/account/images"), Core.ApiKeys.Imgur.Key, Core.ApiKeys.Imgur.Secret, s[0], s[1], "GET", obase.GenerateTimeStamp(), obase.GenerateNonce(), OAuthBase.SignatureTypes.HMACSHA1, out nurl, out nreq);

                                url = nurl + "/?" + nreq + "&oauth_signature=" + sig;

                                /*oauth["consumer_key"] = Core.ApiKeys.Imgur.Key;
                                oauth["consumer_secret"] = Core.ApiKeys.Imgur.Secret;
                                oauth["token"] = s[0];
                                oauth["token_secret"] = s[1];
                                oauth["callback"] = "http://easycaptu.re/";
                                url = "http://api.imgur.com/2/account/images";
                                oauth.GenerateAuthzHeader(url, "POST");
                                foreach (KeyValuePair<string,string> param in oauth._params)
                                {
                                    Out.WriteDebug(param.Key + ": "+param.Value);
                                    //if(param.Key == "token" || param.Key == "callback")
                                        //values.Add("oauth_"+param.Key, param.Value);
                                }*/

                                //Out.WriteDebug("AuthzHeader: " + wc.Headers["Authorization"]);
                            }
                            //if (Core.Imgur_FakeStatus) url += "?_fake_status=200";

                            wc.UploadValuesAsync(new Uri(url), "POST", values);
                        }

                    }
                    catch (Exception z)
                    {
                        Out.WriteError("Something went wrong: " + z.ToString());
                    }
                }
                else Out.WriteDebug("[warning] Screencapture called more then once!!11");
            }
        }
Пример #59
0
        //main
        private void PrintScreen()
        {
            this.Hide();
            form3.Hide();
            Thread.Sleep(300);
            if (this.Visible == false)
            {
                bmp = new Bitmap(blockRegionSize.Width, blockRegionSize.Height);
                gfx = Graphics.FromImage(bmp);
                gfx.CopyFromScreen(upLfSource, upLfDestination, blockRegionSize, CopyPixelOperation.SourceCopy);

                bmp.Save(txtPath.Text + "screen " + pictureNumber.ToString() + "." + imgformat, imgFormat);
                pictureNumber++;
            }
            this.Show();
            if (rbtnModArea.Checked) form3.Show();
        }
Пример #60
-1
        private void ClientBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (_performCapturing)
                {
                    sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                    try
                    {
                        sock.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5656));
                    }
                    catch
                    {
                        MessageBox.Show("Unable to connect!!");
                    }

                    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

                    MemoryStream ms = new MemoryStream();
                    bmpScreenshot.Save(ms, ImageFormat.Png);
                    BinaryWriter bw = new BinaryWriter(ms);
                    byte[] bmpbytes = ms.ToArray();
                    bmpScreenshot.Dispose();
                    ms.Close();

                    sent = SendData(sock, bmpbytes);
                    sock.Close();
                }
            }
         }