How to mirror the camera picture vertically and horizontally in C#

In this guide you will find detailed information on how to flip the image of your IP camera device. 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 flip the captured image of an IP camera device on X, Y or on both axes using C#?

Windows Form WPF  

To establish the connection properly between your application and an IP camera you should apply the same code snippet what you have used in the example (How to connect to an IP camera device using C#?). Important: you should study this article in order to find out how to setup your Windows Forms 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:
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\\Examples\Other\

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:

To find more about the previously used functions included here as well, please, visit this tutorial

Flip(): this is the only additional method of this example. The method belongs to the "Horizontal" and "Vertical" checkboxes that can be seen as buttons on the graphical user interface. The application checks these components until it gets closed. Whenever one of the checkboxes changes, it is going to cause an event that we can listen to. The method adjusts the image orientation of the camera according to these checkboxes.

Implement flip functionality to IP camera in C#


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

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

        public Form1()
            _imageProvider = new DrawingImageProvider();
            _connector = new MediaConnector();
            _videoViewerWf = new VideoViewerWF();

        void SetVideoViewer()
            _videoViewerWf.Size = new Size(260, 180);
            _videoViewerWf.BackColor = Color.Black;
            _videoViewerWf.TabStop = false;
            _videoViewerWf.FlipMode = FlipMode.None;
            _videoViewerWf.Location = new Point(10, 20);
            _videoViewerWf.Name = "_videoViewerWf";

        // Connecting the camera's video channel to the image provider and starting it
        private void button_Connect_Click(object sender, EventArgs e)
            _camera = new IPCamera("rtsp://", "root", "pass");
            _connector.Connect(_camera.VideoChannel, _imageProvider);


        // Flipping the video viewer on the X, Y or both axes
        private void Flip(object sender, EventArgs e)
            var flippedX = HorizontalFlipCheck.Checked;
            var flippedY = VerticalFlipCheck.Checked;

            if (flippedX && flippedY)
                _videoViewerWf.FlipMode = FlipMode.FlipXY;

            if (flippedX)
                _videoViewerWf.FlipMode = FlipMode.FlipX;

            if (flippedY)
                _videoViewerWf.FlipMode = FlipMode.FlipY;

            _videoViewerWf.FlipMode = FlipMode.None;

Code 1 - Implement flip functionality to IP camera 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.


The Graphical User Interface of the application for flipping the image of the camera in C#
Figure 1 - The graphical user interface of your application

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.


	namespace VideoCameraViewer08
    partial class Form1
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>


        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.VerticalFlipCheck = new System.Windows.Forms.CheckBox();
            this.HorizontalFlipCheck = new System.Windows.Forms.CheckBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            // groupBox1
            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(80, 23);
            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(12, 86);
            this.CameraBox.Name = "CameraBox";
            this.CameraBox.Size = new System.Drawing.Size(285, 210);
            this.CameraBox.TabIndex = 3;
            this.CameraBox.TabStop = false;
            this.CameraBox.Text = "Live camera ";
            // VerticalFlipCheck
            this.VerticalFlipCheck.Appearance = System.Windows.Forms.Appearance.Button;
            this.VerticalFlipCheck.AutoSize = true;
            this.VerticalFlipCheck.Location = new System.Drawing.Point(95, 20);
            this.VerticalFlipCheck.Name = "VerticalFlipCheck";
            this.VerticalFlipCheck.Size = new System.Drawing.Size(52, 23);
            this.VerticalFlipCheck.TabIndex = 2;
            this.VerticalFlipCheck.Text = "Vertical";
            this.VerticalFlipCheck.UseVisualStyleBackColor = true;
            this.VerticalFlipCheck.CheckedChanged += new System.EventHandler(this.Flip);
            // HorizontalFlipCheck
            this.HorizontalFlipCheck.Appearance = System.Windows.Forms.Appearance.Button;
            this.HorizontalFlipCheck.AutoSize = true;
            this.HorizontalFlipCheck.Location = new System.Drawing.Point(25, 20);
            this.HorizontalFlipCheck.Name = "HorizontalFlipCheck";
            this.HorizontalFlipCheck.Size = new System.Drawing.Size(64, 23);
            this.HorizontalFlipCheck.TabIndex = 1;
            this.HorizontalFlipCheck.Text = "Horizontal";
            this.HorizontalFlipCheck.UseVisualStyleBackColor = true;
            this.HorizontalFlipCheck.CheckedChanged += new System.EventHandler(this.Flip);
            // groupBox2
            this.groupBox2.Location = new System.Drawing.Point(125, 10);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(170, 60);
            this.groupBox2.TabIndex = 3;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Flip";
            // Form1
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(309, 309);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "IP Camera\'s Image Flipping";


        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button button_Connect;
        private System.Windows.Forms.GroupBox CameraBox;
        private System.Windows.Forms.CheckBox VerticalFlipCheck;
        private System.Windows.Forms.CheckBox HorizontalFlipCheck;
        private System.Windows.Forms.GroupBox groupBox2;

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


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.

Ozeki Camera Recorder

If you are not a developer, but you need a great software to view or record your camera, we recommend you to use Ozeki Camera Recorder. This is a great end user product, that allows you to control your cameras from a webbrowser. It's easy and great. You can download it from the following link: Download Ozeki Camera Recorder.

Download link:
Download Ozeki Camera Recorder for Windows

Copyright © 2000- - Ozeki Ltd |
Home > Online manual > IP video camera viewer > Mirror the camera picture
Legal | Privacy | Terms of use | 6542 | | Login