let height = srcImg.img.Height * width / srcImg.img.Width
imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(srcImg.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic))
stackPreviews.Children.Add(imgCtrl) |> ignore
- imgCtrl.MouseLeftButtonUp.AddHandler(fun obj args -> setCurrentImage (state.SourceImages |> Seq.find (fun srcImg -> (srcImg :> Object) = imgCtrl.Tag)))
+
+ // Zoom to a mouse position into the control 'imgCtrl'.
+ let zoomTo (mousePos: Point) =
+ let canvasW = canvasCurrentImage.ActualWidth * currentScale
+ let canvasH = canvasCurrentImage.ActualHeight * currentScale
+ let centerX = (mousePos.X - imgCtrl.BorderThickness.Left) / (imgCtrl.ActualWidth - imgCtrl.BorderThickness.Left) * canvasW
+ let centerY = (mousePos.Y - imgCtrl.BorderThickness.Top) / (imgCtrl.ActualHeight - imgCtrl.BorderThickness.Top) * canvasH
+ scrollViewCurrentImage.ScrollToHorizontalOffset(centerX - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
+ scrollViewCurrentImage.ScrollToVerticalOffset(centerY - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
+
+ imgCtrl.MouseLeftButtonDown.AddHandler(fun obj args ->
+ setCurrentImage (state.SourceImages |> Seq.find (fun srcImg -> (srcImg :> Object) = imgCtrl.Tag))
+ imgCtrl.UpdateLayout()
+ zoomTo (args.GetPosition(imgCtrl))
+ imgCtrl.CaptureMouse() |> ignore)
+
+ imgCtrl.MouseMove.AddHandler(fun obj args ->
+ if imgCtrl.IsMouseCaptured
+ then
+ zoomTo (args.GetPosition(imgCtrl)))
+
+ imgCtrl.MouseLeftButtonUp.AddHandler(fun obj args ->
+ if imgCtrl.IsMouseCaptured
+ then
+ imgCtrl.ReleaseMouseCapture())
+
let updatePreviews () =
stackPreviews.Children.Clear ()