Skip to main content

Code sample - Resize and crop

Delphi and C# (ActiveX) sample code.

You can resize the image or crop it the way you like. These operations are performed in real-time and with minimal CPU usage.

Resize

Enable resizing or cropping.

VideoCapture1.Video_ResizeOrCrop_Enabled := true;
VideoCapture1.Video_ResizeOrCrop_Enabled = true;

Set width and height

VideoCapture1.Video_Resize_NewWidth := StrToInt(edResizeWidth.Text);
VideoCapture1.Video_Resize_NewHeight := StrToInt(edResizeHeight.Text);
VideoCapture1.Video_Resize_NewWidth = Convert.ToInt32(edResizeWidth.Text);
VideoCapture1.Video_Resize_NewHeight = Convert.ToInt32(edResizeHeight.Text);

The image aspect ratio change mode is letterbox (add black margins to the edges) or stretch.

VideoCapture1.Video_Resize_LetterBox := cbResizeLetterbox.Checked;
VideoCapture1.Video_Resize_LetterBox = cbResizeLetterbox.Checked;

You can also select one of several resizing algorithms. They differ in quality and CPU usage.

case cbResizeMode.ItemIndex of
0: VideoCapture1.Video_Resize_Mode := rm_NearestNeighbor;
1: VideoCapture1.Video_Resize_Mode := rm_Bilinear;
2: VideoCapture1.Video_Resize_Mode := rm_Bilinear_HQ;
3: VideoCapture1.Video_Resize_Mode := rm_Bicubic;
4: VideoCapture1.Video_Resize_Mode := rm_Bicubic_HQ;
end;
switch (cbResizeMode.SelectedIndex)
{
case 0: VideoCapture1.Video_Resize_Mode = VisioForge_Video_Capture_3.TxVFResizeMode.rm_NearestNeighbor; break;
case 1: VideoCapture1.Video_Resize_Mode = VisioForge_Video_Capture_3.TxVFResizeMode. rm_Bilinear; break;
case 2: VideoCapture1.Video_Resize_Mode = VisioForge_Video_Capture_3.TxVFResizeMode.rm_Bilinear_HQ; break;
case 3: VideoCapture1.Video_Resize_Mode = VisioForge_Video_Capture_3.TxVFResizeMode.rm_Bicubic; break;
case 4: VideoCapture1.Video_Resize_Mode = VisioForge_Video_Capture_3.TxVFResizeMode.rm_Bicubic_HQ; break;
};

Crop

Enable resizing or cropping.

VideoCapture1.Video_ResizeOrCrop_Enabled := true;
VideoCapture1.Video_ResizeOrCrop_Enabled = true;

Set area

VideoCapture1.Video_Crop_Left := StrToInt(edCropLeft.Text);
VideoCapture1.Video_Crop_Top := StrToInt(edCropTop.Text);
VideoCapture1.Video_Crop_Right := StrToInt(edCropRight.Text);
VideoCapture1.Video_Crop_Bottom := StrToInt(edCropBottom.Text);
VideoCapture1.Video_Crop_Left = Convert.ToInt32(edCropLeft.Text);
VideoCapture1.Video_Crop_Top = Convert.ToInt32(edCropTop.Text);
VideoCapture1.Video_Crop_Right = Convert.ToInt32(edCropRight.Text);
VideoCapture1.Video_Crop_Bottom = Convert.ToInt32(edCropBottom.Text);

Please get in touch with support to get help with this tutorial. Visit our GitHub page to get more code samples.