private void button1_Click(object sender, EventArgs e) { try { if (current > 1) { current = 0; args.Clear(); } var x = int.Parse(this.textBoxX.Text); var y = int.Parse(this.textBoxY.Text); var w = int.Parse(this.textBoxW.Text); var h = int.Parse(this.textBoxH.Text); var setting = new EventDrivenCapture.CaptureSetting(x, y, w, h); setting.ID = current; args.Add(new EventDrivenCapture.Capture(setting)); var bitmap = new Bitmap(w, h); Graphics captureGraphics = Graphics.FromImage(bitmap); captureGraphics.CopyFromScreen(x, y, 0, 0, new Size(w, h)); switch (current) { case 0: this.pictureBox1.Image = bitmap; break; case 1: this.pictureBox2.Image = bitmap; break; default: break; } current++; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public Capture(CaptureSetting setting) { _setting = setting; CapturedImage = new Bitmap(setting.Width, setting.Height, PixelFormat.Format32bppArgb); // for reusing bitmap }