MilleVisionNotes

This site focuses on practical examples of controlling Basler industrial cameras
using the pylon SDK and C#, based on real-world development experience.

Zoom & Pan for WPF Live View Using TransformGroup (C# / .NET 8)

Zoom&Pan

In the previous article, we built a minimal setup to overlay a HUD (FPS, exposure, gain) on top of live video. As a continuation, this article adds mouse-driven zoom/pan, an ROI rectangle that follows the image, and a crosshair fixed to the screen center.

We keep the same layer-separated design (Video = zoom/pan, HUD = fixed) to minimize blur and jitter.


Environment / Prerequisites


Goals

  • Mouse wheel zoom centered at the cursor (1.1× per step)
  • Shift + drag (or middle button drag) to pan
  • ROI rectangle scales/moves with the image (follows zoom/pan)
  • Crosshair stays fixed in screen coordinates (HUD layer)

XAML: Two Layers + ROI Layer (Shared Transform)

Because the implementation has grown, some parts are omitted where appropriate.


HalfConverter (For Center Crosshair)

This converter makes it easy to draw lines centered in the HUD layer.


Code-Behind: Zoom / Pan

In this article, zoom and pan are implemented purely in code-behind. You can refactor into ViewModel/Model later if needed.


ROI Handling and Applying It in Real Apps

In this sample, we assign the same TransformGroup to both the Image and the RoiLayer.

  • Because RoiLayer shares the transform, it naturally follows zoom/pan.
  • In real applications, you typically bind Canvas.Left/Top/Width/Height of RoiRect to a ViewModel, then apply those values to camera ROI parameters.
  • When applying ROI to the camera, remember GenICam constraints such as width/height increments.

Meanwhile, HUD elements (crosshair, texts) remain transform-free and screen-fixed, preventing blur and keeping interaction intuitive.


Example Screens

The UI looks like this:

ROIZoomDefault.png

Pan the live view by dragging while holding Shift. The ROI follows; the crosshair stays fixed.

ROIZoomTrans.png

Zoom with the mouse wheel. The zoom ratio in the upper area updates as well.

ROIZoomZoom.png

Use Fit to fit the image to the window. 1:1 sets the zoom to 1.0, and Reset returns zoom to 1.0 and pan offset to 0.

ROIZoomFit.png


Summary

  • Video + ROI share the same transform; HUD stays fixed (layered design)
  • Mouse interaction provides cursor-centered zoom and intuitive pan
  • ROI follows the image while the crosshair remains screen-fixed

コメント

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA