Water wave
Using water wave you can create water-like effect on images. By moving the trackbars, you can adjust the measure of horizontal waves count and amplitude and also the measure of vertical ones.
Important: you should study this article in order to find out how to setup your Windows Forms Application correctly.
Properties
HorizontalWavesCount: With this option you can set the number of horizontal distortions.
VerticalWavesCount: With this option you can set the number of vertical distortions.
VerticalWavesAmplitude: With this option you can set the size of a vertical distortion.
HorizontalWavesAmplitude: With this option you can set the size of a horizontal distortion.
| 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 OzWaterWave _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 OzWaterWave();
}
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 hwc_TrackScroll(object sender, EventArgs e)
{
var trackBar_hwc = sender as TrackBar;
if (trackBar_hwc != null)
{
var value = trackBar_hwc.Value;
_filter.HorizontalWavesCount = value;
lb_hwc.Text = @"Horizontal waves count : " + value;
}
}
private void hwa_TrackScroll(object sender, EventArgs e)
{
var trackBar_hwa = sender as TrackBar;
if (trackBar_hwa != null)
{
var value = trackBar_hwa.Value;
_filter.VerticalWavesAmplitude = value;
lb_hwa.Text = @"Horizontal waves amplitude : " + value;
}
}
private void vwc_TrackScroll(object sender, EventArgs e)
{
var trackBar_vwc = sender as TrackBar;
if (trackBar_vwc != null)
{
var value = trackBar_vwc.Value;
_filter.VerticalWavesCount = value;
lb_vwc.Text = @"Vertical waves count : " + value;
}
}
private void vwa_TrackScroll(object sender, EventArgs e)
{
var trackBar_vwa = sender as TrackBar;
if (trackBar_vwa != null)
{
var value = trackBar_vwa.Value;
_filter.VerticalWavesAmplitude = value;
lb_vwa.Text = @"Vertical waves amplitude : " + value;
}
}
}
}
Code 1 Water wave 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_hwc = new System.Windows.Forms.TrackBar();
this.trackBar_hwa = new System.Windows.Forms.TrackBar();
this.trackBar_vwc = new System.Windows.Forms.TrackBar();
this.lb_hwc = new System.Windows.Forms.Label();
this.lb_hwa = new System.Windows.Forms.Label();
this.lb_vwc = new System.Windows.Forms.Label();
this.btn_add = new System.Windows.Forms.Button();
this.btn_remove = new System.Windows.Forms.Button();
this.groupBox = new System.Windows.Forms.GroupBox();
this.trackBar_vwa = new System.Windows.Forms.TrackBar();
this.lb_vwa = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.trackBar_hwc)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar_hwa)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar_vwc)).BeginInit();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar_vwa)).BeginInit();
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_hwc
//
this.trackBar_hwc.Location = new System.Drawing.Point(159, 32);
this.trackBar_hwc.Maximum = 255;
this.trackBar_hwc.Minimum = 1;
this.trackBar_hwc.Name = "trackBar_hwc";
this.trackBar_hwc.Size = new System.Drawing.Size(315, 45);
this.trackBar_hwc.TabIndex = 15;
this.trackBar_hwc.Value = 2;
this.trackBar_hwc.Scroll += new System.EventHandler(this.hwc_TrackScroll);
//
// trackBar_hwa
//
this.trackBar_hwa.Location = new System.Drawing.Point(159, 83);
this.trackBar_hwa.Maximum = 255;
this.trackBar_hwa.Minimum = 1;
this.trackBar_hwa.Name = "trackBar_hwa";
this.trackBar_hwa.Size = new System.Drawing.Size(315, 45);
this.trackBar_hwa.TabIndex = 16;
this.trackBar_hwa.Value = 2;
this.trackBar_hwa.Scroll += new System.EventHandler(this.hwa_TrackScroll);
//
// trackBar_vwc
//
this.trackBar_vwc.Location = new System.Drawing.Point(159, 134);
this.trackBar_vwc.Maximum = 255;
this.trackBar_vwc.Minimum = 1;
this.trackBar_vwc.Name = "trackBar_vwc";
this.trackBar_vwc.Size = new System.Drawing.Size(315, 45);
this.trackBar_vwc.TabIndex = 17;
this.trackBar_vwc.Value = 2;
this.trackBar_vwc.Scroll += new System.EventHandler(this.vwc_TrackScroll);
//
// lb_hwc
//
this.lb_hwc.AutoSize = true;
this.lb_hwc.Location = new System.Drawing.Point(6, 32);
this.lb_hwc.Name = "lb_hwc";
this.lb_hwc.Size = new System.Drawing.Size(121, 13);
this.lb_hwc.TabIndex = 18;
this.lb_hwc.Text = "Horizontal waves count:";
//
// lb_hwa
//
this.lb_hwa.AutoSize = true;
this.lb_hwa.Location = new System.Drawing.Point(6, 83);
this.lb_hwa.Name = "lb_hwa";
this.lb_hwa.Size = new System.Drawing.Size(139, 13);
this.lb_hwa.TabIndex = 19;
this.lb_hwa.Text = "Horizontal waves amplitude:";
//
// lb_vwc
//
this.lb_vwc.AutoSize = true;
this.lb_vwc.Location = new System.Drawing.Point(6, 134);
this.lb_vwc.Name = "lb_vwc";
this.lb_vwc.Size = new System.Drawing.Size(109, 13);
this.lb_vwc.TabIndex = 20;
this.lb_vwc.Text = "Vertical waves count:";
//
// 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);
//
// groupBox
//
this.groupBox.Controls.Add(this.lb_vwa);
this.groupBox.Controls.Add(this.trackBar_vwa);
this.groupBox.Controls.Add(this.lb_vwc);
this.groupBox.Controls.Add(this.lb_hwa);
this.groupBox.Controls.Add(this.lb_hwc);
this.groupBox.Controls.Add(this.trackBar_vwc);
this.groupBox.Controls.Add(this.trackBar_hwa);
this.groupBox.Controls.Add(this.trackBar_hwc);
this.groupBox.Location = new System.Drawing.Point(9, 407);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(483, 244);
this.groupBox.TabIndex = 23;
this.groupBox.TabStop = false;
this.groupBox.Text = "Water wave settings";
//
// trackBar_vwa
//
this.trackBar_vwa.Location = new System.Drawing.Point(159, 186);
this.trackBar_vwa.Maximum = 255;
this.trackBar_vwa.Minimum = 1;
this.trackBar_vwa.Name = "trackBar_vwa";
this.trackBar_vwa.Size = new System.Drawing.Size(315, 45);
this.trackBar_vwa.TabIndex = 21;
this.trackBar_vwa.Value = 1;
this.trackBar_vwa.Scroll += new System.EventHandler(this.vwa_TrackScroll);
//
// lb_vwa
//
this.lb_vwa.AutoSize = true;
this.lb_vwa.Location = new System.Drawing.Point(9, 186);
this.lb_vwa.Name = "lb_vwa";
this.lb_vwa.Size = new System.Drawing.Size(127, 13);
this.lb_vwa.TabIndex = 22;
this.lb_vwa.Text = "Vertical waves amplitude:";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(501, 663);
this.Controls.Add(this.groupBox);
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 = "Water wave";
((System.ComponentModel.ISupportInitialize)(this.trackBar_hwc)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar_hwa)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar_vwc)).EndInit();
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar_vwa)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Ozeki.Media.VideoViewerWF videoViewer;
private System.Windows.Forms.Button btn_Connect;
private System.Windows.Forms.TrackBar trackBar_hwc;
private System.Windows.Forms.TrackBar trackBar_hwa;
private System.Windows.Forms.TrackBar trackBar_vwc;
private System.Windows.Forms.Label lb_hwc;
private System.Windows.Forms.Label lb_hwa;
private System.Windows.Forms.Label lb_vwc;
private System.Windows.Forms.Button btn_add;
private System.Windows.Forms.Button btn_remove;
private System.Windows.Forms.GroupBox groupBox;
private System.Windows.Forms.Label lb_vwa;
private System.Windows.Forms.TrackBar trackBar_vwa;
}
}
Code 2 Water wave GUI in C#
Conclusion
With the help of this lecture you can successfully implement water wave 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:
-
What kind of developer environment is needed?
- Microsoft Visual Studio 2010
- Microsoft .Net Framework 4.0
- Internet connection
-
How can I get the URL of the camera?
You can get the URL from the producer of the camera.
-
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.