How to adjust Pan, Tilt and Zoom speed in C#

In this guide you can find information on how to adjust pan, tilt and zoom speed of your camera with your Windows Forms/WPF Application written in C#. To implement this example, you need to have Ozeki Camera SDK installed, and a reference to OzekiSDK.dll should be added to your Visual Studio project.

How to adjust Pan, Tilt and Zoom speed using C#?

To implement Pan-Tilt-Zoom control you should apply the same code snippet you have used in the How to implement Pan-Tilt-Zoom (PTZ) control example. Important: you should study this article in order to find out how to setup your Windows Forms/WPF Application correctly.

Getting started

To get started it is recomended to Download and Install the latest version of Ozeki Camera SDK. After installation you can find the example code discussed in this page with full source code in the following location on your harddisk:

Download Ozeki Camera SDK: https://www.camera-sdk.com/p_6513-download-onvif-ozeki-camera-sdk-for-c-sharp.html
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\examples.zip\Examples\Other\
PTZ_Speed_WF\PTZ_Speed_WF.sln
WPF version: C:\Program Files\Ozeki\Ozeki SDK\examples.zip\Examples\Other\
PTZ_Speed_WPF\PTZ_Speed_WPF.sln

To compile this example you will need Microsoft Visual Studio installed on your computer.

The additional statements and methods of this example are the following:

Whenever you press a PTZ button, you should adjust pan, tilt and zoom speed in the Move() method by the query values of three trackbars:

_camera.CameraMovement.PanSpeed = (float)trackBar_Pan.Value/100;
_camera.CameraMovement.TiltSpeed = (float)trackBar_Tilt.Value/100;
_camera.CameraMovement.ZoomSpeed = (float)trackBar_Zoom.Value/100;

Note: pan, tilt and zoom speed is a float value ranging between 0 and 1, so we'll have to divide the values of the trackbars by 100.

In addition, you can display the trackbars's value on the GUI labels to inform the user by the trackbars scroll event.

Adjust Pan, Tilt and Zoom speed example in C#

Windows Form WPF  

Windows forms version

Form1.cs

using System;
using System.Drawing;
using System.Windows.Forms;
using Ozeki.Media;
using Ozeki.Camera;

namespace PTZ_Camera_Motion_Control05
{
    public partial class Form1 : Form
    {
        private IIPCamera _camera;
        private DrawingImageProvider _imageProvider;
        private MediaConnector _connector;
        private VideoViewerWF _videoViewerWf;

        public Form1()
        {
            InitializeComponent();
            _imageProvider = new DrawingImageProvider();
            _connector = new MediaConnector();
            _videoViewerWf = new VideoViewerWF();
            SetVideoViewer();
        }

        private void SetVideoViewer()
        {
            CameraBox.Controls.Add(_videoViewerWf);
            _videoViewerWf.Size = new Size(260, 180);
            _videoViewerWf.BackColor = Color.Black;
            _videoViewerWf.TabStop = false;
            _videoViewerWf.Location = new Point(14, 19);
            _videoViewerWf.Name = "_videoViewerWf";
        }

        private void button_Connect_Click(object sender, EventArgs e)
        {
            _camera=new IPCamera("192.168.112.109:8080","user","qwe123");
            _connector.Connect(_camera.VideoChannel, _imageProvider);
            _videoViewerWf.SetImageProvider(_imageProvider);
            _videoViewerWf.Start();
            _camera.Start();
        }

        private void MouseDownMove(object sender, MouseEventArgs e)
        {
            var button = sender as Button;
            if (button != null)
                Move(button.Text);
        }

        private void MouseUpMove(object sender, MouseEventArgs e)
        {
            if(_camera!=null)
            _camera.CameraMovement.StopMovement();
        }

        private void Move(string direction)
        {
            if (_camera == null) return;
            _camera.CameraMovement.PanSpeed = (float)trackBar_Pan.Value / 100;
            _camera.CameraMovement.TiltSpeed = (float)trackBar_Tilt.Value / 100;
            _camera.CameraMovement.ZoomSpeed = (float)trackBar_Zoom.Value / 100;
            switch (direction)
            {
                case "Up Left":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.LeftUp);
                    break;
                case "Up":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Up);
                    break;
                case "Up Right":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.RightUp);
                    break;
                case "Left":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Left);
                    break;
                case "Right":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Right);
                    break;
                case "Down Left":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.LeftDown);
                    break;
                case "Down":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Down);
                    break;
                case "Down Right":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.RightDown);
                    break;
                case "In":
                    _camera.CameraMovement.Zoom(CameraMovement.In);
                    break;
                case "Out":
                    _camera.CameraMovement.Zoom(CameraMovement.Out);
                    break;
            }
        }

        private void trackBar_Pan_Scroll(object sender, EventArgs e)
        {
            label_Pan.Text = trackBar_Pan.Value.ToString();
        }

        private void trackBar_Tilt_Scroll(object sender, EventArgs e)
        {
            label_Tilt.Text = trackBar_Tilt.Value.ToString();
        }

        private void trackBar_Zoom_Scroll(object sender, EventArgs e)
        {
            label_Zoom.Text = trackBar_Zoom.Value.ToString();
        }
    }
}
	

Code 1 - Adjust Pan, Tilt and Zoom speed example in C#

Please note that none of the cancel and disconnect methods are included in the example because of the demonstrating intent and briefness of the article.

GUI

the gui of your app
Figure 1 - The graphical user interface of your application

After the successful implementation of the functions and the GUI elements, the application will work properly. Pressing the connect button will load in the image of the IP camera device, connected to your PC, into the panel that you can see on the picture.

Below you can find the code that belongs to the interface of the previously presented application. With the help of this section your Windows Forms Application will be able to work properly.

Form1.Designer.cs

	namespace PTZ_Camera_Motion_Control05
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.button_Connect = new System.Windows.Forms.Button();
            this.CameraBox = new System.Windows.Forms.GroupBox();
            this.CameraMoveBox = new System.Windows.Forms.GroupBox();
            this.buttonDownRight = new System.Windows.Forms.Button();
            this.buttonRight = new System.Windows.Forms.Button();
            this.buttonUpRight = new System.Windows.Forms.Button();
            this.buttonDown = new System.Windows.Forms.Button();
            this.buttonUp = new System.Windows.Forms.Button();
            this.buttonDownLeft = new System.Windows.Forms.Button();
            this.buttonLeft = new System.Windows.Forms.Button();
            this.buttonUpLeft = new System.Windows.Forms.Button();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.button_ZoomOut = new System.Windows.Forms.Button();
            this.button_ZoomIn = new System.Windows.Forms.Button();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.label_Zoom = new System.Windows.Forms.Label();
            this.label_Tilt = new System.Windows.Forms.Label();
            this.label_Pan = new System.Windows.Forms.Label();
            this.trackBar_Zoom = new System.Windows.Forms.TrackBar();
            this.trackBar_Tilt = new System.Windows.Forms.TrackBar();
            this.trackBar_Pan = new System.Windows.Forms.TrackBar();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.CameraMoveBox.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_Zoom)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_Tilt)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_Pan)).BeginInit();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.button_Connect);
            this.groupBox1.Location = new System.Drawing.Point(10, 10);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(100, 60);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Connect";
            // 
            // button_Connect
            // 
            this.button_Connect.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.button_Connect.ForeColor = System.Drawing.Color.Black;
            this.button_Connect.Location = new System.Drawing.Point(10, 20);
            this.button_Connect.Name = "button_Connect";
            this.button_Connect.Size = new System.Drawing.Size(75, 25);
            this.button_Connect.TabIndex = 6;
            this.button_Connect.Text = "Connect";
            this.button_Connect.UseVisualStyleBackColor = true;
            this.button_Connect.Click += new System.EventHandler(this.button_Connect_Click);
            // 
            // CameraBox
            // 
            this.CameraBox.Location = new System.Drawing.Point(10, 80);
            this.CameraBox.Name = "CameraBox";
            this.CameraBox.Size = new System.Drawing.Size(290, 210);
            this.CameraBox.TabIndex = 3;
            this.CameraBox.TabStop = false;
            this.CameraBox.Text = "Live camera ";
            // 
            // CameraMoveBox
            // 
            this.CameraMoveBox.Controls.Add(this.buttonDownRight);
            this.CameraMoveBox.Controls.Add(this.buttonRight);
            this.CameraMoveBox.Controls.Add(this.buttonUpRight);
            this.CameraMoveBox.Controls.Add(this.buttonDown);
            this.CameraMoveBox.Controls.Add(this.buttonUp);
            this.CameraMoveBox.Controls.Add(this.buttonDownLeft);
            this.CameraMoveBox.Controls.Add(this.buttonLeft);
            this.CameraMoveBox.Controls.Add(this.buttonUpLeft);
            this.CameraMoveBox.Location = new System.Drawing.Point(10, 300);
            this.CameraMoveBox.Name = "CameraMoveBox";
            this.CameraMoveBox.Size = new System.Drawing.Size(290, 115);
            this.CameraMoveBox.TabIndex = 4;
            this.CameraMoveBox.TabStop = false;
            this.CameraMoveBox.Text = "Control";
            // 
            // buttonDownRight
            // 
            this.buttonDownRight.Location = new System.Drawing.Point(205, 80);
            this.buttonDownRight.Name = "buttonDownRight";
            this.buttonDownRight.Size = new System.Drawing.Size(75, 25);
            this.buttonDownRight.TabIndex = 7;
            this.buttonDownRight.Text = "Down Right";
            this.buttonDownRight.UseVisualStyleBackColor = true;
            this.buttonDownRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonDownRight.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonRight
            // 
            this.buttonRight.Location = new System.Drawing.Point(205, 50);
            this.buttonRight.Name = "buttonRight";
            this.buttonRight.Size = new System.Drawing.Size(75, 25);
            this.buttonRight.TabIndex = 6;
            this.buttonRight.Text = "Right";
            this.buttonRight.UseVisualStyleBackColor = true;
            this.buttonRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonRight.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonUpRight
            // 
            this.buttonUpRight.Location = new System.Drawing.Point(205, 20);
            this.buttonUpRight.Name = "buttonUpRight";
            this.buttonUpRight.Size = new System.Drawing.Size(75, 25);
            this.buttonUpRight.TabIndex = 5;
            this.buttonUpRight.Text = "Up Right";
            this.buttonUpRight.UseVisualStyleBackColor = true;
            this.buttonUpRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonUpRight.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonDown
            // 
            this.buttonDown.Location = new System.Drawing.Point(105, 80);
            this.buttonDown.Name = "buttonDown";
            this.buttonDown.Size = new System.Drawing.Size(75, 25);
            this.buttonDown.TabIndex = 4;
            this.buttonDown.Text = "Down";
            this.buttonDown.UseVisualStyleBackColor = true;
            this.buttonDown.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonDown.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonUp
            // 
            this.buttonUp.Location = new System.Drawing.Point(105, 20);
            this.buttonUp.Name = "buttonUp";
            this.buttonUp.Size = new System.Drawing.Size(75, 23);
            this.buttonUp.TabIndex = 3;
            this.buttonUp.Text = "Up";
            this.buttonUp.UseVisualStyleBackColor = true;
            this.buttonUp.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonUp.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonDownLeft
            // 
            this.buttonDownLeft.Location = new System.Drawing.Point(10, 80);
            this.buttonDownLeft.Name = "buttonDownLeft";
            this.buttonDownLeft.Size = new System.Drawing.Size(75, 25);
            this.buttonDownLeft.TabIndex = 2;
            this.buttonDownLeft.Text = "Down Left";
            this.buttonDownLeft.UseVisualStyleBackColor = true;
            this.buttonDownLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonDownLeft.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonLeft
            // 
            this.buttonLeft.Location = new System.Drawing.Point(10, 50);
            this.buttonLeft.Name = "buttonLeft";
            this.buttonLeft.Size = new System.Drawing.Size(75, 25);
            this.buttonLeft.TabIndex = 1;
            this.buttonLeft.Text = "Left";
            this.buttonLeft.UseVisualStyleBackColor = true;
            this.buttonLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonLeft.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // buttonUpLeft
            // 
            this.buttonUpLeft.Location = new System.Drawing.Point(10, 20);
            this.buttonUpLeft.Name = "buttonUpLeft";
            this.buttonUpLeft.Size = new System.Drawing.Size(75, 25);
            this.buttonUpLeft.TabIndex = 0;
            this.buttonUpLeft.Text = "Up Left";
            this.buttonUpLeft.UseVisualStyleBackColor = true;
            this.buttonUpLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.buttonUpLeft.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.button_ZoomOut);
            this.groupBox2.Controls.Add(this.button_ZoomIn);
            this.groupBox2.Location = new System.Drawing.Point(10, 420);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(290, 60);
            this.groupBox2.TabIndex = 5;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Zoom";
            // 
            // button_ZoomOut
            // 
            this.button_ZoomOut.Location = new System.Drawing.Point(205, 20);
            this.button_ZoomOut.Name = "button_ZoomOut";
            this.button_ZoomOut.Size = new System.Drawing.Size(75, 25);
            this.button_ZoomOut.TabIndex = 1;
            this.button_ZoomOut.Text = "Out";
            this.button_ZoomOut.UseVisualStyleBackColor = true;
            this.button_ZoomOut.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.button_ZoomOut.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // button_ZoomIn
            // 
            this.button_ZoomIn.Location = new System.Drawing.Point(10, 20);
            this.button_ZoomIn.Name = "button_ZoomIn";
            this.button_ZoomIn.Size = new System.Drawing.Size(75, 25);
            this.button_ZoomIn.TabIndex = 0;
            this.button_ZoomIn.Text = "In";
            this.button_ZoomIn.UseVisualStyleBackColor = true;
            this.button_ZoomIn.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMove);
            this.button_ZoomIn.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMove);
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.label_Zoom);
            this.groupBox3.Controls.Add(this.label_Tilt);
            this.groupBox3.Controls.Add(this.label_Pan);
            this.groupBox3.Controls.Add(this.trackBar_Zoom);
            this.groupBox3.Controls.Add(this.trackBar_Tilt);
            this.groupBox3.Controls.Add(this.trackBar_Pan);
            this.groupBox3.Controls.Add(this.label3);
            this.groupBox3.Controls.Add(this.label2);
            this.groupBox3.Controls.Add(this.label1);
            this.groupBox3.Location = new System.Drawing.Point(10, 485);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(290, 115);
            this.groupBox3.TabIndex = 6;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Speed settings";
            // 
            // label_Zoom
            // 
            this.label_Zoom.AutoSize = true;
            this.label_Zoom.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.label_Zoom.Location = new System.Drawing.Point(244, 85);
            this.label_Zoom.Name = "label_Zoom";
            this.label_Zoom.Size = new System.Drawing.Size(27, 15);
            this.label_Zoom.TabIndex = 8;
            this.label_Zoom.Text = "100";
            // 
            // label_Tilt
            // 
            this.label_Tilt.AutoSize = true;
            this.label_Tilt.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.label_Tilt.Location = new System.Drawing.Point(244, 55);
            this.label_Tilt.Name = "label_Tilt";
            this.label_Tilt.Size = new System.Drawing.Size(27, 15);
            this.label_Tilt.TabIndex = 7;
            this.label_Tilt.Text = "100";
            // 
            // label_Pan
            // 
            this.label_Pan.AutoSize = true;
            this.label_Pan.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.label_Pan.Location = new System.Drawing.Point(244, 25);
            this.label_Pan.Name = "label_Pan";
            this.label_Pan.Size = new System.Drawing.Size(27, 15);
            this.label_Pan.TabIndex = 6;
            this.label_Pan.Text = "100";
            // 
            // trackBar_Zoom
            // 
            this.trackBar_Zoom.AutoSize = false;
            this.trackBar_Zoom.Location = new System.Drawing.Point(90, 80);
            this.trackBar_Zoom.Maximum = 100;
            this.trackBar_Zoom.Name = "trackBar_Zoom";
            this.trackBar_Zoom.Size = new System.Drawing.Size(155, 30);
            this.trackBar_Zoom.TabIndex = 5;
            this.trackBar_Zoom.Value = 100;
            this.trackBar_Zoom.Scroll += new System.EventHandler(this.trackBar_Zoom_Scroll);
            // 
            // trackBar_Tilt
            // 
            this.trackBar_Tilt.AutoSize = false;
            this.trackBar_Tilt.Location = new System.Drawing.Point(90, 50);
            this.trackBar_Tilt.Maximum = 100;
            this.trackBar_Tilt.Name = "trackBar_Tilt";
            this.trackBar_Tilt.Size = new System.Drawing.Size(155, 30);
            this.trackBar_Tilt.TabIndex = 4;
            this.trackBar_Tilt.Value = 100;
            this.trackBar_Tilt.Scroll += new System.EventHandler(this.trackBar_Tilt_Scroll);
            // 
            // trackBar_Pan
            // 
            this.trackBar_Pan.AutoSize = false;
            this.trackBar_Pan.Location = new System.Drawing.Point(90, 20);
            this.trackBar_Pan.Maximum = 100;
            this.trackBar_Pan.Name = "trackBar_Pan";
            this.trackBar_Pan.Size = new System.Drawing.Size(155, 30);
            this.trackBar_Pan.TabIndex = 3;
            this.trackBar_Pan.Value = 100;
            this.trackBar_Pan.Scroll += new System.EventHandler(this.trackBar_Pan_Scroll);
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(10, 85);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(69, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Zoom speed:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(10, 55);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(58, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Tilt Speed:";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(10, 25);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(61, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Pan speed:";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(314, 614);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.CameraMoveBox);
            this.Controls.Add(this.CameraBox);
            this.Controls.Add(this.groupBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "PTZ Camera Speed Adjustment";
            this.groupBox1.ResumeLayout(false);
            this.CameraMoveBox.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_Zoom)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_Tilt)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_Pan)).EndInit();
            this.ResumeLayout(false);

        }

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button button_Connect;
        private System.Windows.Forms.GroupBox CameraBox;
        private System.Windows.Forms.GroupBox CameraMoveBox;
        private System.Windows.Forms.Button buttonDownRight;
        private System.Windows.Forms.Button buttonRight;
        private System.Windows.Forms.Button buttonUpRight;
        private System.Windows.Forms.Button buttonDown;
        private System.Windows.Forms.Button buttonUp;
        private System.Windows.Forms.Button buttonDownLeft;
        private System.Windows.Forms.Button buttonLeft;
        private System.Windows.Forms.Button buttonUpLeft;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.Button button_ZoomOut;
        private System.Windows.Forms.Button button_ZoomIn;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.Label label_Zoom;
        private System.Windows.Forms.Label label_Tilt;
        private System.Windows.Forms.Label label_Pan;
        private System.Windows.Forms.TrackBar trackBar_Zoom;
        private System.Windows.Forms.TrackBar trackBar_Tilt;
        private System.Windows.Forms.TrackBar trackBar_Pan;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
    }
}
	

Code 2 - GUI example in C#


WPF version

MainWindow.xaml.cs

using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Ozeki.Media;
using Ozeki.Camera;

namespace PTZ_Camera_Motion_Control05Wpf
{
    /// 
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window
    {
        private IIPCamera _camera;
        private DrawingImageProvider _drawingImageProvider;
        private MediaConnector _connector;

        public MainWindow()
        {
            InitializeComponent();

            _drawingImageProvider = new DrawingImageProvider();
            _connector = new MediaConnector();
            videoViewer.SetImageProvider(_drawingImageProvider);
        }

        private void Connect_Click(object sender, RoutedEventArgs e)
        {
            _camera=new IPCamera("192.168.112.109:8080","user","qwe123");

            _connector.Connect(_camera.VideoChannel, _drawingImageProvider);
            _camera.Start();
            videoViewer.Start();
        }

        private void MouseDownMove(object sender, MouseButtonEventArgs e)
        {
            var button = sender as Button;
            if (button != null) Move(button.Content.ToString());
        }

        private void MouseUpMove(object sender, MouseButtonEventArgs e)
        {
            if(_camera!=null)
            _camera.CameraMovement.StopMovement();
        }

        private void Move(string direction)
        {
            if (_camera == null) return;
            _camera.CameraMovement.PanSpeed = (float)trackBar_Pan.Value / 100;
            _camera.CameraMovement.TiltSpeed = (float)trackBar_Tilt.Value / 100;
            _camera.CameraMovement.ZoomSpeed = (float)trackBar_Zoom.Value / 100;
            switch (direction)
            {
                case "Up Left":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.LeftUp);
                    break;
                case "Up":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Up);
                    break;
                case "Up Right":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.RightUp);
                    break;
                case "Left":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Left);
                    break;
                case "Right":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Right);
                    break;
                case "Down Left":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.LeftDown);
                    break;
                case "Down":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.Down);
                    break;
                case "Down Right":
                    _camera.CameraMovement.ContinuousMove(MoveDirection.RightDown);
                    break;
                case "In":
                    _camera.CameraMovement.Zoom(CameraMovement.In);
                    break;
                case "Out":
                    _camera.CameraMovement.Zoom(CameraMovement.Out);
                    break;
            }
        }

        private void trackBar_Pan_Scroll(object sender, MouseButtonEventArgs e)
        {
            label_Pan.Content = trackBar_Pan.Value.ToString(CultureInfo.InvariantCulture);
        }

        private void trackBar_Tilt_Scroll(object sender, MouseButtonEventArgs e)
        {
            label_Tilt.Content = trackBar_Tilt.Value.ToString(CultureInfo.InvariantCulture);
        }

        private void trackBar_Zoom_Scroll(object sender, MouseButtonEventArgs e)
        {
            label_Zoom.Content = trackBar_Zoom.Value.ToString(CultureInfo.InvariantCulture);
        }
    }
}
	

Code 1 - Adjust Pan, Tilt and Zoom speed example in C#

Please note that none of the cancel and disconnect methods are included in the example because of the demonstrating intent and briefness of the article.

GUI

the gui of your app
Figure 1 - The graphical user interface of your application

After the successful implementation of the functions and the GUI elements, the application will work properly. Pressing the connect button will load in the image of the IP camera device, connected to your PC, into the panel that you can see on the picture.

Below you can find the code that belongs to the interface of the previously presented application. With the help of this section your WPF Application will be able to work properly.

MainWindow.xaml

	<Window x:Class="PTZ_Camera_Motion_Control05Wpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:Ozeki.Media;assembly=OzekiSDK"
        Title="PTZ camera speed adjusment" Height="733" Width="336" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
    <Grid>
        <GroupBox Header="Live camera" HorizontalAlignment="Left" Margin="10,82,0,0" VerticalAlignment="Top" Height="226" Width="308">
            <Grid HorizontalAlignment="Left" Height="204" VerticalAlignment="Top" Width="296">
                <controls:VideoViewerWPF Name="videoViewer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black"/>
            </Grid>
        </GroupBox>
        <GroupBox Header="Connect" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="67" Width="91">
            <Button Content="Connect" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" RenderTransformOrigin="-0.107,-0.364" Click="Connect_Click" Margin="0,10,0,0"/>
        </GroupBox>
        <GroupBox Header="Control" HorizontalAlignment="Left" Margin="12,313,0,0" VerticalAlignment="Top" Height="154" Width="308">
            <Grid HorizontalAlignment="Left" Height="132" VerticalAlignment="Top" Width="296">
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>

                <Button Grid.Row="0" Grid.Column="0" Content="Up Left" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
                <Button Grid.Row="0" Grid.Column="1" Content="Up" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
                <Button Grid.Row="0" Grid.Column="2" Content="Up Right" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>

                <Button Grid.Row="1" Grid.Column="0" Content="Left" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
                <Button Grid.Row="1" Grid.Column="2" Content="Right" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>

                <Button Grid.Row="2" Grid.Column="0" Content="Down Left" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
                <Button Grid.Row="2" Grid.Column="1" Content="Down" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
                <Button Grid.Row="2" Grid.Column="2" Content="Down Right" Margin="5" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
            </Grid>
        </GroupBox>
        <GroupBox Header="Zoom" HorizontalAlignment="Left" Margin="12,472,0,0" VerticalAlignment="Top" Height="61" Width="306">
            <Grid HorizontalAlignment="Left" Height="39" VerticalAlignment="Top" Width="294">
                <Button Content="In" HorizontalAlignment="Left" VerticalAlignment="Center" Width="75" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
                <Button Content="Out" HorizontalAlignment="Right" VerticalAlignment="Center" Width="75" PreviewMouseLeftButtonDown="MouseDownMove" PreviewMouseLeftButtonUp="MouseUpMove"/>
            </Grid>
        </GroupBox>
        
        <GroupBox Header="Speed settings" HorizontalAlignment="Left" Margin="12,538,0,0" VerticalAlignment="Top" Height="155" Width="306">
            <Grid HorizontalAlignment="Left" Height="132" VerticalAlignment="Top" Width="296">
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="4*"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                
                <Label Content="Pan speed:" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Label Content="Tilt speed:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Label Content="Zoom speed:" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Slider x:Name="trackBar_Pan" Grid.Row="0"  Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="150" PreviewMouseUp="trackBar_Pan_Scroll" Maximum="100" Value="100"/>
                <Slider x:Name="trackBar_Tilt" Grid.Row="1"  Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="150" PreviewMouseUp="trackBar_Tilt_Scroll" Maximum="100" Value="100"/>
                <Slider x:Name="trackBar_Zoom" Grid.Row="2"  Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="150" PreviewMouseUp="trackBar_Zoom_Scroll" Maximum="100" Value="100"/>
                <Label x:Name="label_Pan" Content="" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Label x:Name="label_Tilt" Content="" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Label x:Name="label_Zoom" Content="" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>

            </Grid>
        </GroupBox>
    </Grid>
	</Window>

	

Code 2 - GUI example in C#

DISCLAIMER: Please note that the following features will only work if your IP camera supports the given function. You should check the user manual of your IP camera to make sure it supports the feature that you wish to implement in C#.

Related Pages

FAQ

Below you can find the answers for the most frequently asked questions related to this topic:

  1. How can I get the URL of the camera?

    You can get the URL from the producer of the camera. (In the 10th tutorial you can find information on how to create an own IP camera discoverer program.)

  2. I have not managed to build the solution. How to solve it?

    • Please set the Target framework property of the project to .NET 4.0.
    • You should add the System.Drawing.dll and the OzekiSDK.dll to the references of the solution.
    • Please import the missing classes.
  3. Why cannot I set the pan/tilt/zoom speed ?

    Some camera does not support it.

More information