Skip to content

Cropping and zooming

Cropping

An area of the video source can easily be cropped:

  1. Define a cropping size with Cropping_Width and Cropping_Height.
  2. Enable the cropping with Cropping_Enabled.
  3. Start the preview, recording or playback.
  4. The cropping area can now be moved with Cropping_X and Cropping_Y, even dynamically during the preview, recording or playback.

Trackbar bounds

When trackbars are used to move the cropped area over the video window, the maximum positions of these trackbars are returned by the Cropping_XMax and Cropping_YMax properties. The best place to update the trackbar bounds is the OnResizeVideo event, e.g.:

procedure TForm1.VideoGrabberResizeVideo(Sender: TObject; SourceWidth, SourceHeight: Integer);
begin
  TrackBarX.Min:= 0;
  TrackBarX.Max:= VideoGrabber.Cropping_XMax;
  TrackBarX.Position:= VideoGrabber.Cropping_X;

  TrackBarY.Min:= 0;
  TrackBarY.Max:= VideoGrabber.Cropping_YMax;
  TrackBarY.Position:= VideoGrabber.Cropping_Y;
end;

Zooming

A cropped area can be zoomed as follows:

  1. Define a cropping size with Cropping_Width and Cropping_Height.
  2. Enable the cropping with Cropping_Enabled.
  3. Start the preview, recording or playback.
  4. A zooming coefficient can now be specified dynamically with Cropping_Zoom.
  5. The cropping area can also be moved with Cropping_X and Cropping_Y.

Note

If the zooming area is near an edge of the video frame, changing Cropping_Zoom makes the video image "move" in the opposite direction.

To prevent this problem, enable the Cropping_Outbounds property. This keeps the zooming location fixed against the edges; as a trade-off, a black border appears when Cropping_X and Cropping_Y are near the edges.