private void CanvasPanel_MouseMove(object sender, MouseEventArgs e) { if (_isMouseDown) { var x = Mouse.GetPosition(CanvasPanel).X; var y = Mouse.GetPosition(CanvasPanel).Y; if (x >= _ellipseHalfWidth && x <= CanvasImage.Width - _ellipseHalfWidth - 1 && y >= _ellipseHalfHeight && y <= CanvasImage.Height - _ellipseHalfHeight - 1) { try { var croppedBitmap = new CroppedBitmap(ColorImage.Source as BitmapSource, new Int32Rect(Convert.ToInt32(x), Convert.ToInt32(y), 1, 1)); var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); MoveEllipse(x, y, SelectedColor); UpdateTextBox(); ColorRectangle.Fill = new SolidColorBrush(SelectedColor); } catch (Exception) { _isMouseDown = false; SetColor(Colors.White); } finally { CanvasImage.InvalidateVisual(); } } else { _isMouseDown = false; } } }