public void GetBBox() { if (_bboxStartPoint != null && _bboxEndPoint != null && _selectedImage != null) { var left = Math.Min((float)_bboxStartPoint.Value.X, (float)_bboxEndPoint.Value.X); var right = Math.Max((float)_bboxStartPoint.Value.X, (float)_bboxEndPoint.Value.X); var top = Math.Min((float)_bboxStartPoint.Value.Y, (float)_bboxEndPoint.Value.Y); var bottom = Math.Max((float)_bboxStartPoint.Value.Y, (float)_bboxEndPoint.Value.Y); if (left < 0) { left = 0; } if (right > ActualWidth) { right = (float)ActualWidth; } if (top < 0) { top = 0; } if (bottom > ActualHeight) { bottom = (float)ActualHeight; } var width = right - left; var height = bottom - top; if ((width * height) > 0.001) // mouse false positives { var a = new Annotation { Cx = (float)((left + width / 2.0d) / ActualWidth), Cy = (float)((top + height / 2.0d) / ActualHeight), Width = (float)(width / ActualWidth), Height = (float)(height / ActualHeight) }; _selectedImage.AddAnnotation(a); } } }