private void GetSnapshot() { var p = MousePosition; var scaling = Util.GetScalingFactor(); p.X = (int)(p.X * scaling); p.Y = (int)(p.Y * scaling); p.X -= (int)(_mSnapshot.Width * scaling) / 2; p.Y -= (int)(_mSnapshot.Height * scaling) / 2; using (var dc = Graphics.FromImage(_mSnapshot)) { dc.CopyFromScreen(p, new Point(0, 0), _mSnapshot.Size); Refresh(); //Invalidate(); var center = Util.Center(new RectangleF(0, 0, _mSnapshot.Size.Width, _mSnapshot.Size.Height)); var c = _mSnapshot.GetPixel((int)Math.Ceiling(center.X), (int)Math.Ceiling(center.Y)); if (c == SelectedColor) { return; } SelectedColor = c; SelectedColorChanged?.Invoke(this, null); } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if ((e.Button & MouseButtons.Left) != MouseButtons.Left) { return; } Cursor = Cursors.Cross; //Remember that the monitor dpi setting can change while the app is running, //so we really need to check this each time we start capturing. _dpiScaleFactor = Util.GetScalingFactor(); _isCapturing = true; Invalidate(); }