cv_demo.zip
axis.dll
cv.exe
dlink.dll
dshow.dll
jpeg.dll
local.dll
mjpeg.dll
multisource.dll
panasonic.dll
pixord.dll
stardot.dll
stream.dll
videosource.dll
cv_src.zip
axis
axis.csproj.user
cv
bin
Debug
Release
Controls
cv.csproj.user
Forms
Tools
dlink
dlink.csproj.user
dshow
Core
dshow.csproj.user
icons
about.png
fit_to_size.png
folder.png
folder-opened.png
table.png
text_braille.png
videocamera.ico
videocamera_stop.png
window_sidebar.png
jpeg
jpeg.csproj.user
local
local.csproj.user
mjpeg
mjpeg.csproj.user
multisource
multisource.csproj.user
panasonic
panasonic.csproj.user
pixord
pixord.csproj.user
stardot
stardot.csproj.user
stream
stream.csproj.user
videosource
videosource.csproj.user
|
// Camera Vision
//
// Copyright � Andrew Kirillov, 2005-2006
// andrew.kirillov@gmail.com
//
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Threading;
namespace CameraViewer
{
/// <summary>
/// Summary description for CameraWindow.
/// </summary>
public class CameraWindow : System.Windows.Forms.Control
{
private Camera camera = null;
private bool autosize = false;
private bool needSizeUpdate = false;
private bool firstFrame = true;
// AutoSize property
[DefaultValue(false)]
public bool AutoSize
{
get { return autosize; }
set
{
autosize = value;
UpdatePosition();
}
}
// Camera property
[Browsable(false)]
public Camera Camera
{
get { return camera; }
set
{
// lock
Monitor.Enter(this);
// detach event
if (camera != null)
{
camera.NewFrame -= new EventHandler(camera_NewFrame);
}
camera = value;
needSizeUpdate = true;
firstFrame = true;
// atach event
if (camera != null)
{
camera.NewFrame += new EventHandler(camera_NewFrame);
}
// unlock
Monitor.Exit(this);
}
}
// Constructor
public CameraWindow()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer |
ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
}
// Paint control
protected override void OnPaint(PaintEventArgs pe)
{
if ((needSizeUpdate) || (firstFrame))
{
UpdatePosition();
needSizeUpdate = false;
}
// lock
Monitor.Enter(this);
Graphics g = pe.Graphics;
Rectangle rc = this.ClientRectangle;
Pen pen = new Pen(Color.Black, 1);
// draw rectangle
g.DrawRectangle(pen, rc.X, rc.Y, rc.Width - 1, rc.Height - 1);
if (camera != null)
{
camera.Lock();
// draw frame
if (camera.LastFrame != null)
{
g.DrawImage(camera.LastFrame, rc.X + 1, rc.Y + 1, rc.Width - 2, rc.Height - 2);
firstFrame = false;
}
else
{
// Create font and brush
Font drawFont = new Font("Arial", 12);
SolidBrush drawBrush = new SolidBrush(Color.White);
g.DrawString("Connecting ...", drawFont, drawBrush, new PointF(5, 5));
drawBrush.Dispose();
drawFont.Dispose();
}
camera.Unlock();
}
pen.Dispose();
// unlock
Monitor.Exit(this);
base.OnPaint(pe);
}
// update position and size of the control
public void UpdatePosition()
{
// lock
Monitor.Enter(this);
if (autosize)
{
Rectangle rc = this.Parent.ClientRectangle;
int width = 320;
int height = 240;
if (camera != null)
{
camera.Lock();
// get frame dimension
if (camera.LastFrame != null)
{
width = camera.LastFrame.Width;
height = camera.LastFrame.Height;
}
camera.Unlock();
}
//
this.SuspendLayout();
this.Location = new Point((rc.Width - width - 2) / 2, (rc.Height - height - 2) / 2);
this.Size = new Size(width + 2, height + 2);
this.ResumeLayout();
}
// unlock
Monitor.Exit(this);
}
// On new frame ready
private void camera_NewFrame(object sender, System.EventArgs e)
{
Invalidate();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like
AForge.NET.
Going out of computers I am just a man loving his family, enjoying traveling, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...