Pixellate

Pixellation means displaying additional pixels in an are to distort the shapes and curves of the displayed image and make the impression of bad resolution. It is very useful when you want to something (e.g. a face in the crime news) or there is something which is not supposed to be on the picture (e.g. the combination of a safe). You also have the options to adjust the width, height and size of the created pixels.

Properties

Important: You should study this article in order to find out how to setup your Windows Forms Application correctly.

PixelHeight: With this option we can set the height of the pixels.

PixelWidth: With this option we can set the width of the pixels.

PixelSize: With this option we can set the size of the pixels. It adjusts both the width and the height of the pixels

original#
Figure 1 - Original image

modified#
Figure 2 - Modified image with pixellate effect

Windows Form  

Windows forms version

MainForm.cs

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

namespace ImageManipulation_WF
{
    public partial class MainForm : Form
    {
        private ICamera _camera;
        private DrawingImageProvider _imageProvider;
        private MediaConnector _connector;

        #region Initialize manipulation and filter
        private ImageManipulation _manipulation;
        private OzPixellate _filter;
        #endregion

        public MainForm()
        {
            InitializeComponent();

            _connector = new MediaConnector();
            _imageProvider = new DrawingImageProvider();
            // Create video viewer UI control

            // Bind the camera image to the UI control
            videoViewer.SetImageProvider(_imageProvider);

            _manipulation = new ImageManipulation();
            _manipulation.Start();

            _filter = new OzPixellate();
        }

        private void btn_Connect_Click(object sender, EventArgs e)
        {
            _camera = new WebCamera();

            if (_camera == null) return;

            _connector.Connect(_camera.VideoChannel, _manipulation);
            _connector.Connect(_manipulation, _imageProvider);

            _camera.Start();
            videoViewer.Start();
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            _manipulation.Add(_filter);
        }

        private void btn_Remove_Click(object sender, EventArgs e)
        {
            _manipulation.Remove(_filter);
        }

        private void ph_TrackScroll(object sender, EventArgs e)
        {
            var trackBar_ph = sender as TrackBar;
            if (trackBar_ph != null)
            {
                var value = trackBar_ph.Value;
                _filter.PixelHeight = value;
                lb_height.Text = @"Pixel height: " + value;
            }
        }

        private void pw_TrackScroll(object sender, EventArgs e)
        {
            var trackBar_pw = sender as TrackBar;
            if (trackBar_pw != null)
            {
                var value = trackBar_pw.Value;
                _filter.PixelWidth = value;
                lb_width.Text = @"Pixel width: " + value;
            }
        }

        private void ps_TrackScroll(object sender, EventArgs e)
        {
            var trackBar_ps = sender as TrackBar;
            if (trackBar_ps != null)
            {
                var value = trackBar_ps.Value;
                _filter.PixelSize = value;
                lb_size.Text = @"Pixel size: " + value;
            }
        }
    }
}

Code 1 Pixellate in C#

GUI

Windows forms version

MainForm.Designer.cs

namespace ImageManipulation_WF
{
    partial class MainForm
    {
        /// 
        /// Required designer variable.
        /// 
        private System.ComponentModel.IContainer components = null;

        /// 
        /// Clean up any resources being used.
        /// 
        /// true if managed resources should be disposed; otherwise, false.
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// 
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 
        private void InitializeComponent()
        {
            this.videoViewer = new Ozeki.Media.VideoViewerWF();
            this.btn_Connect = new System.Windows.Forms.Button();
            this.trackBar_ph = new System.Windows.Forms.TrackBar();
            this.trackBar_pw = new System.Windows.Forms.TrackBar();
            this.trackBar_ps = new System.Windows.Forms.TrackBar();
            this.lb_height = new System.Windows.Forms.Label();
            this.lb_width = new System.Windows.Forms.Label();
            this.lb_size = new System.Windows.Forms.Label();
            this.btn_add = new System.Windows.Forms.Button();
            this.btn_remove = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_ph)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_pw)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_ps)).BeginInit();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // videoViewer
            // 
            this.videoViewer.BackColor = System.Drawing.Color.Black;
            this.videoViewer.FlipMode = Ozeki.Media.FlipMode.None;
            this.videoViewer.FrameStretch = Ozeki.Media.FrameStretch.Uniform;
            this.videoViewer.FullScreenEnabled = true;
            this.videoViewer.Location = new System.Drawing.Point(12, 57);
            this.videoViewer.Name = "videoViewer";
            this.videoViewer.RotateAngle = 0;
            this.videoViewer.Size = new System.Drawing.Size(471, 334);
            this.videoViewer.TabIndex = 0;
            this.videoViewer.Text = "videoViewerWF1";
            // 
            // btn_Connect
            // 
            this.btn_Connect.Location = new System.Drawing.Point(12, 12);
            this.btn_Connect.Name = "btn_Connect";
            this.btn_Connect.Size = new System.Drawing.Size(152, 26);
            this.btn_Connect.TabIndex = 14;
            this.btn_Connect.Text = "Connect to WebCamera";
            this.btn_Connect.UseVisualStyleBackColor = true;
            this.btn_Connect.Click += new System.EventHandler(this.btn_Connect_Click);
            // 
            // trackBar_ph
            // 
            this.trackBar_ph.Location = new System.Drawing.Point(113, 32);
            this.trackBar_ph.Maximum = 32;
            this.trackBar_ph.Minimum = 2;
            this.trackBar_ph.Name = "trackBar_ph";
            this.trackBar_ph.Size = new System.Drawing.Size(361, 45);
            this.trackBar_ph.TabIndex = 15;
            this.trackBar_ph.Value = 2;
            this.trackBar_ph.Scroll += new System.EventHandler(this.ph_TrackScroll);
            // 
            // trackBar_pw
            // 
            this.trackBar_pw.Location = new System.Drawing.Point(113, 83);
            this.trackBar_pw.Maximum = 32;
            this.trackBar_pw.Minimum = 2;
            this.trackBar_pw.Name = "trackBar_pw";
            this.trackBar_pw.Size = new System.Drawing.Size(361, 45);
            this.trackBar_pw.TabIndex = 16;
            this.trackBar_pw.Value = 2;
            this.trackBar_pw.Scroll += new System.EventHandler(this.pw_TrackScroll);
            // 
            // trackBar_ps
            // 
            this.trackBar_ps.Location = new System.Drawing.Point(113, 134);
            this.trackBar_ps.Maximum = 32;
            this.trackBar_ps.Minimum = 2;
            this.trackBar_ps.Name = "trackBar_ps";
            this.trackBar_ps.Size = new System.Drawing.Size(361, 45);
            this.trackBar_ps.TabIndex = 17;
            this.trackBar_ps.Value = 2;
            this.trackBar_ps.Scroll += new System.EventHandler(this.ps_TrackScroll);
            // 
            // lb_height
            // 
            this.lb_height.AutoSize = true;
            this.lb_height.Location = new System.Drawing.Point(6, 32);
            this.lb_height.Name = "lb_height";
            this.lb_height.Size = new System.Drawing.Size(64, 13);
            this.lb_height.TabIndex = 18;
            this.lb_height.Text = "Pixel height:";
            // 
            // lb_width
            // 
            this.lb_width.AutoSize = true;
            this.lb_width.Location = new System.Drawing.Point(6, 83);
            this.lb_width.Name = "lb_width";
            this.lb_width.Size = new System.Drawing.Size(60, 13);
            this.lb_width.TabIndex = 19;
            this.lb_width.Text = "Pixel width:";
            // 
            // lb_size
            // 
            this.lb_size.AutoSize = true;
            this.lb_size.Location = new System.Drawing.Point(6, 134);
            this.lb_size.Name = "lb_size";
            this.lb_size.Size = new System.Drawing.Size(53, 13);
            this.lb_size.TabIndex = 20;
            this.lb_size.Text = "Pixel size:";
            // 
            // btn_add
            // 
            this.btn_add.Location = new System.Drawing.Point(315, 14);
            this.btn_add.Name = "btn_add";
            this.btn_add.Size = new System.Drawing.Size(75, 23);
            this.btn_add.TabIndex = 21;
            this.btn_add.Text = "Add";
            this.btn_add.UseVisualStyleBackColor = true;
            this.btn_add.Click += new System.EventHandler(this.btn_Add_Click);
            // 
            // btn_remove
            // 
            this.btn_remove.Location = new System.Drawing.Point(408, 14);
            this.btn_remove.Name = "btn_remove";
            this.btn_remove.Size = new System.Drawing.Size(75, 23);
            this.btn_remove.TabIndex = 22;
            this.btn_remove.Text = "Remove";
            this.btn_remove.UseVisualStyleBackColor = true;
            this.btn_remove.Click += new System.EventHandler(this.btn_Remove_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.lb_size);
            this.groupBox1.Controls.Add(this.lb_width);
            this.groupBox1.Controls.Add(this.lb_height);
            this.groupBox1.Controls.Add(this.trackBar_ps);
            this.groupBox1.Controls.Add(this.trackBar_pw);
            this.groupBox1.Controls.Add(this.trackBar_ph);
            this.groupBox1.Location = new System.Drawing.Point(9, 407);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(483, 194);
            this.groupBox1.TabIndex = 23;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Pixel settings";
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(501, 620);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.btn_remove);
            this.Controls.Add(this.btn_add);
            this.Controls.Add(this.btn_Connect);
            this.Controls.Add(this.videoViewer);
            this.Name = "MainForm";
            this.Text = "Pixellate";
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_ph)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_pw)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_ps)).EndInit();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private Ozeki.Media.VideoViewerWF videoViewer;
        private System.Windows.Forms.Button btn_Connect;
        private System.Windows.Forms.TrackBar trackBar_ph;
        private System.Windows.Forms.TrackBar trackBar_pw;
        private System.Windows.Forms.TrackBar trackBar_ps;
        private System.Windows.Forms.Label lb_height;
        private System.Windows.Forms.Label lb_width;
        private System.Windows.Forms.Label lb_size;
        private System.Windows.Forms.Button btn_add;
        private System.Windows.Forms.Button btn_remove;
        private System.Windows.Forms.GroupBox groupBox1;
    }
}
		

Code 2 Pixellate GUI in C#

Conclusion

With the help of this lecture you can successfully implement Pixellate effect with your C# camera application using the Ozeki Camera SDK.

Related Pages

FAQ

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

  1. What kind of developer environment is needed?

    • Microsoft Visual Studio 2010
    • Microsoft .Net Framework 4.0
    • Internet connection
  2. How can I get the URL of the camera?

    You can get the URL from the producer of the camera.

  3. 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 OzekiSDK.dll to the references of the solution.
    • Please import the missing classes.

More information