private void PbCaptureBox_MouseMove(object sender, MouseEventArgs e) //영역그리는 중 { if (drawingCaptureBoxsStart && captureMouseDown) { mousePosition = e.Location; captureMouseMove = true; PbCaptureBox.Invalidate(); } }
private void InitializeCapturing() //캡처 초기화 { PbCaptureBox.Invalidate(); PbCaptureBox.Location = new Point(0, 0); PbCaptureBox.Size = new Size(0, 0); PbCaptureBox.Visible = false; drawingCaptureBoxsStart = false; captureMouseDown = false; captureMouseMove = false; PbCaptureBox.SendToBack(); }
private void PrepareCapture() // 캡쳐 준비 { drawingCaptureBoxsStart = true; Screen[] screens = Screen.AllScreens; int fullScreenWidth = 0; int fullScreenHeight = 0; for (int i = 0; i < screens.Length; i++) { fullScreenWidth += screens[i].Bounds.Width; fullScreenHeight += screens[i].Bounds.Height; } Rectangle fullScreenBox = new Rectangle(0, 0, fullScreenWidth, fullScreenHeight); Bitmap fullScreenBitMap = new Bitmap(fullScreenBox.Width, fullScreenBox.Height); Graphics fullScreenCanvas = Graphics.FromImage(fullScreenBitMap); fullScreenCanvas.CopyFromScreen(fullScreenBox.Left, fullScreenBox.Top, 0, 0, fullScreenBox.Size); //메인폼 스타일 조정 this.FormBorderStyle = FormBorderStyle.None; this.Width = fullScreenBox.Width; this.Height = fullScreenBox.Height; this.Left = fullScreenBox.Left; this.Top = fullScreenBox.Top; PbCaptureBox.Image = fullScreenBitMap; // 전체 화면 캡쳐 이미지 PbCaptureBox.Size = new Size(fullScreenBox.Width, fullScreenBox.Height); PbCaptureBox.Left = fullScreenBox.Left; PbCaptureBox.Top = fullScreenBox.Top; PbCaptureBox.Visible = true; PbCaptureBox.BringToFront(); }
private void PbCaptureBox_MouseUp(object sender, MouseEventArgs e) //영역 지정 완료 { PbCaptureBox.Invalidate(); captureTargetSet = false; if (drawingCaptureBoxsStart && captureMouseDown && captureMouseMove) { try { Rectangle capturedImgBox = CreateRectangle(); Bitmap capturedImgBitMap = new Bitmap(capturedImgBox.Width - 1, capturedImgBox.Height - 1); Graphics capturedImgCanvas = Graphics.FromImage(capturedImgBitMap); capturedImgCanvas.CopyFromScreen(capturedImgBox.Left + 1, capturedImgBox.Top + 1, 0, 0, capturedImgBitMap.Size); PbCapturedImg.Image = capturedImgBitMap; captureTarget = new Rectangle(new Point(capturedImgBox.Left + 1, capturedImgBox.Top + 1), capturedImgBitMap.Size); captureTargetSet = true; BtnStartCapture.BackColor = Color.Aquamarine; } catch (Exception ex) { logger.Fatal("Exception Occured at MouseUp Process : " + ex.Message); StopCapturing(); } finally { StopCapturing(); } } }