public void ChangeFrame(object sender, CursorEventArgs e) { CursorAdorner cusorAdoner = sender as CursorAdorner; BitmapSource img = cusorAdoner.Image; double R = img.DpiX * 0.4; Int32Rect rect = new Int32Rect(); rect.X = (int)(e.Position.X - R); rect.Y = (int)(e.Position.Y - R); rect.Width = (int)(2 * R); rect.Height = (int)(2 * R); if (rect.X + rect.Width >= img.PixelWidth) { rect.X -= (int)(rect.X + rect.Width - img.PixelWidth + 1); } if (rect.Y + rect.Height >= img.PixelHeight) { rect.Y -= (int)(rect.Y + rect.Height - img.PixelHeight + 1); } if (rect.X < 0) { rect.Width += rect.X; if (rect.Width < 1) { rect.Width = 1; } rect.X = 0; } if (rect.Y < 0) { rect.Height += rect.Y; if (rect.Height < 1) { rect.Height = 1; } rect.Y = 0; } System.Windows.Controls.Image imageControl = _adornedElement as System.Windows.Controls.Image; imageControl.Source = new CroppedBitmap(img, rect); //if (_cursorband.Data == null) updateCursor(); }
private void WindowLoaded(object sender, RoutedEventArgs e) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(ImageLarge); CursorSelector = new CursorAdorner(ImageLarge); layer.Add(CursorSelector); CursorSelector.Cursorband.Visibility = Visibility.Hidden; AdornerLayer layerPrecise = AdornerLayer.GetAdornerLayer(ImageSmall); PreciseSelector = new PreciseAdoner(ImageSmall); PreciseSelector.Window = this; layerPrecise.Add(PreciseSelector); PreciseSelector.Cursorband.Visibility = Visibility.Hidden; CursorSelector.CursorChanged += new EventHandler <CursorEventArgs>(PreciseSelector.ChangeFrame); CursorSelector.CursorChanged += new EventHandler <CursorEventArgs>(this.ChangeCursorPosition); PreciseSelector.CursorChanged += new EventHandler <CursorEventArgs>(CursorSelector.ChangeCursorPosition); }