/// <summary> /// Sets the new rectangle of an object in pixels. /// </summary> /// <param name="rect">The new rectangle of an object in pixels.</param> protected override void SetRect(Rectangle rect) { VintasoftImage image = _imageViewer.Image; if (image != null) { // get transform from control to the device independent pixels (DIP) AffineMatrix matrix = _imageViewer.GetTransformFromControlToDip(); // convert location to the DIP PointF locationInDip = PointFAffineTransform.TransformPoint(matrix, rect.Location); if (HideContentOnTransform) { // if comment control content is visible if (!_isCommentControlContentHidden) { // hide comment control content UpdateCommentControlContentVisibility(false); _isCommentControlContentHidden = true; } } // update comment bounding box CommentControl.Comment.BoundingBox = new RectangleF(locationInDip, rect.Size); } }
/// <summary> /// Returns center point of image viewer in coordinate space of specified image. /// </summary> /// <param name="image">An image.</param> /// <returns> /// Center point of image viewer in coordinate space of specified image. /// </returns> private PointF GetCenterPoint(VintasoftImage image) { // get old visible point PointF centerPoint = new PointF(ImageViewer.ClientSize.Width / 2.0f, ImageViewer.ClientSize.Height / 2.0f); // get transform from image space to viewer space AffineMatrix pointTransfrom = ImageViewer.GetTransformFromControlToImage(image); // transform the point return(PointFAffineTransform.TransformPoint(pointTransfrom, centerPoint)); }
/// <summary> /// Returns distance between point and image rectangle. /// </summary> /// <param name="point">A point in image viewer space.</param> /// <param name="image">An image.</param> /// <returns>Distance between point and image rectangle.</returns> private float GetDistanceBetweenPointAndImageRect(PointF point, VintasoftImage image) { AffineMatrix transformMatrix = ImageViewer.GetTransformFromImageToControl(image); // get image rectangle RectangleF imageRect = new RectangleF(0, 0, image.Width, image.Height); PointFTransform pointTransform = PointFAffineTransform.FromMatrix(transformMatrix); imageRect = PointFAffineTransform.TransformBoundingBox(pointTransform, imageRect); PointF imagePoint = PointF.Empty; // get X coordinate of point on image if (point.X < imageRect.X) { imagePoint.X = imageRect.X; } else if (point.X > imageRect.X + imageRect.Width) { imagePoint.X = imageRect.X + imageRect.Width; } else { imagePoint.X = point.X; } // get Y coordinate of point on image if (point.Y < imageRect.Y) { imagePoint.Y = imageRect.Y; } else if (point.Y > imageRect.Y + imageRect.Height) { imagePoint.Y = imageRect.Y + imageRect.Height; } else { imagePoint.Y = point.Y; } // calculate distance float dx = (point.X - imagePoint.X); float dy = (point.Y - imagePoint.Y); float distanceBetweenImageAndPoint = dx * dx + dy * dy; return(distanceBetweenImageAndPoint); }
/// <summary> /// Gets an array that contains reference points in content space of this annotation. /// </summary> /// <returns></returns> public virtual PointF[] GetReferencePointsInContentSpace() { float width = Size.Width; float height = Size.Height; float w = Math.Min(width / 10, height / 10); PointF[] points; switch (MarkType) { case MarkAnnotationType.Rectangle: points = new PointF[] { new PointF(-width / 2, -height / 2), new PointF(width / 2, -height / 2), new PointF(width / 2, height / 2), new PointF(-width / 2, height / 2) }; break; case MarkAnnotationType.Tick: points = new PointF[] { new PointF(-width / 2, 0), new PointF(0, height / 4), new PointF(width / 2, -height / 2), new PointF(0, height / 2), new PointF(-width / 2, 0) }; break; case MarkAnnotationType.Cross: points = new PointF[] { new PointF(-width / 2, -w), new PointF(-w, -w), new PointF(-w, -height / 2), new PointF(w, -height / 2), new PointF(w, -w), new PointF(width / 2, -w), new PointF(width / 2, w), new PointF(w, w), new PointF(w, height / 2), new PointF(-w, height / 2), new PointF(-w, w), new PointF(-width / 2, w) }; break; case MarkAnnotationType.Star: points = new PointF[] { new PointF(-width / 2, 0), new PointF(-w, -w), new PointF(0, -height / 2), new PointF(w, -w), new PointF(width / 2, 0), new PointF(w, w), new PointF(0, height / 2), new PointF(-w, w), new PointF(-width / 2, 0) }; break; default: throw new NotImplementedException(); } AffineMatrix matrix = new AffineMatrix(); if (HorizontalMirrored) { matrix.ScalePrepend(-1, 1); } if (VerticalMirrored) { matrix.ScalePrepend(1, -1); } PointFAffineTransform.TransformPoints(matrix, points); return(points); }