public DragAdorner(UIElement adorned) : base(adorned) { var brush = new VisualBrush(adorned) {Stretch = Stretch.None, AlignmentX = AlignmentX.Left}; // HACK: this makes the markers work properly, // even after adding 4+ markers and then removing to 3-, // and then shift-dragging (in which case the size of the adorner is correct, // but the VisualBrush tries to render the now invisible number. _child = new Rectangle(); _child.BeginInit(); _child.Width = adorned.RenderSize.Width; _child.Height = adorned.RenderSize.Height; _child.Fill = brush; _child.IsHitTestVisible = false; _child.EndInit(); var animation = new DoubleAnimation(0.6, 0.85, new Duration(TimeSpan.FromMilliseconds(500))) {AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever}; animation.Freeze(); brush.BeginAnimation(Brush.OpacityProperty, animation); }
private void InputImage_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var inputPoint = e.GetPosition(InputImage); var RenderPoint = e.GetPosition(MainCanvas); points.Add(inputPoint); renderPoints.Add(RenderPoint); if (points.Count % 2 == 0 && points.Count > 1) { int index = points.Count - 1; Shapes.Rectangle rectangle = new Shapes.Rectangle(); var x = Math.Min(renderPoints[index].X, renderPoints[index - 1].X); var y = Math.Min(renderPoints[index].Y, renderPoints[index - 1].Y); rectangle.BeginInit(); RectangleInit(index, rectangle, x, y); rectangle.EndInit(); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); var realPointX = Math.Min(points[index].X, points[index - 1].X); var realPointY = Math.Min(points[index].Y, points[index - 1].Y); rect.X = (int)realPointX; rect.Y = (int)realPointY; rect.Width = (int)rectangle.Width; rect.Height = (int)rectangle.Height; sperartor.AddCropArea(rect, nowBitmap); } }