Example #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);
            }
        }
Example #2
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;
 }
        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)
            {

            }
        }
Example #4
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;
        }
Example #5
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();
        }
Example #6
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);
        }
Example #7
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++;
             }
         }
     }
 }
        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)
            {

            }
        }
Example #9
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;
        }
Example #10
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");
            }
        }
Example #11
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);
        }
Example #12
0
 private void capture()
 {
     printscreen = new Bitmap(intWidth, intHeight);
     gfx = Graphics.FromImage(printscreen as Image);
     gfx.CopyFromScreen(intTop, intleft, 0, 0, printscreen.Size);
 }
Example #13
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;
        }
Example #14
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();
            }
        }
Example #15
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();
        }
Example #16
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
            }
        }
Example #17
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
        }
Example #18
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;
        }
Example #19
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();
            }
        }
        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);
                }
            }
        }
        //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();
        }
Example #22
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);
 }
Example #23
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();
        }
        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);
        }
Example #25
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();
            }
        }
Example #26
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);
        }
Example #27
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();
        }
Example #28
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);
 }
        /// <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;
            }
        }
Example #30
-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();
                }
            }
         }