public override void OnMouseMove(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left || !this.IsSelected || isDrawn) { return; } var ptSecond = Element.ToImageCoordinate(e.Location).ToPt().Round(); roi = new RectangleF { X = System.Math.Min(ptFirst.X, ptSecond.X), Y = System.Math.Min(ptFirst.Y, ptSecond.Y), Width = System.Math.Abs(ptFirst.X - ptSecond.X), Height = System.Math.Abs(ptFirst.Y - ptSecond.Y) }; roi.Width = Math.Max(MIN_RECT_SIZE, roi.Width); roi.Height = Math.Max(MIN_RECT_SIZE, roi.Height); roi.Height = 1.2f * roi.Width; //fix width-height ratio var imageSize = Element.Image.Size.ToSize(); this.Annotation.Polygon = roi.Vertices().Select(x => x.Clamp(imageSize)).ToArray(); }
public override void OnMouseUp(object sender, MouseEventArgs e) { if (Element.Image == null || !this.IsSelected || isDrawn) { return; } var vertices = roi.Vertices(); this.Annotation.Polygon = vertices; isDrawn = true; }