• 大小: 404KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: C#
  • 标签: 摄像头  CAMERA  拍照  

资源简介

这是我用C#写的摄像头控件,可以预览,拍照。 把项目添加到解决方案中,然后新建一个窗体,从工具箱中把CameraView控件拖到窗体上,再写一句:CameraView1.Start() 就启动了。 要拍照,请调用:cameraView1.TakePicture(filename); 本人心血啊!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DirectShowLib;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.Threading;
using System.Diagnostics;

namespace CameraLib
{
    [Guid(“A264F504-DE24-4fda-A27C-C319F7593C2C“)]
    public partial class CameraView : UserControl
    {
        public CameraView()
        {
            InitializeComponent();
            m_state = CameraState.Stop;
            Enabled = false;
        }

        private void CameraView_Load(object sender EventArgs e)
        {
            Control topcontrol = Parent;
            while (topcontrol != null)
            {
                if (topcontrol is Form)
                {
                    Form fm = topcontrol as Form;
                    fm.FormClosed += new FormClosedEventHandler(fm_FormClosed);
                    break;
                }
                topcontrol = topcontrol.Parent;
            }
        }

        void fm_FormClosed(object sender FormClosedEventArgs e)
        {
            Stop();
        }

        Thread eventthread;

        MyCapture cam = null;
                
        bool maincamera = true;
        [Category(“CAMERA“)]
        [Description(“是否使用主摄像头“)]
        [DefaultValue(true)]
        public bool MainCamera { get { return maincamera; } set { maincamera = value; } }

        int width = 320;
        [Category(“CAMERA“)]
        [Description(“截图宽度“)]
        [DefaultValue(320)]
        public int PictureWidth { get { return width; } set { width = value; } }

        int height = 240;
        [Category(“CAMERA“)]
        [Description(“截图高度“)]
        [DefaultValue(240)]
        public int PictureHeight { get { return height; } set { height = value; } }

        CameraState m_state;
        [Category(“CAMERA“)]
        [Description(“运行状态“)]
        public CameraState State
        {
            get { return m_state; }
            private set
            {
                if (m_state != value)
                {
                    m_state = value;
                    if (onStateChanged != null)
                    {
                        MethodInvoker mi = delegate()
                        {
                            onStateChanged(m_state);
                        };
                        if (Parent.InvokeRequired)
                            Parent.Invoke(mi);
                        else 
                            mi();
                    }
                }
            }
        }

        public enum CameraState
        {
            Stop Run
        }

        public delegate void StateHandler(CameraState state);

        [Category(“CAMERA“)]
        [Description(“状态变化事件“)]
        public event StateHandler onStateChanged = null;

        public List sizes

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-04-13 21:10  CameraLib\bin\
     目录           0  2013-04-13 21:11  CameraLib\bin\Debug\
     文件       19968  2013-04-13 21:11  CameraLib\bin\Debug\CameraLib.dll
     文件       52736  2013-04-13 21:11  CameraLib\bin\Debug\CameraLib.pdb
     文件      282624  2013-03-29 16:37  CameraLib\bin\Debug\DirectShowLib-2005.dll
     目录           0  2013-04-13 21:10  CameraLib\bin\x86\
     目录           0  2013-04-10 18:26  CameraLib\bin\x86\Debug\
     文件       19968  2013-04-03 16:49  CameraLib\bin\x86\Debug\CameraLib.dll
     文件       44544  2013-04-03 16:49  CameraLib\bin\x86\Debug\CameraLib.pdb
     文件      282624  2013-03-29 16:37  CameraLib\bin\x86\Debug\DirectShowLib.dll
     文件        4053  2013-04-13 21:11  CameraLib\CameraLib.csproj
     文件         168  2013-04-04 00:57  CameraLib\CameraLib.csproj.user
     文件        7216  2013-04-04 01:08  CameraLib\CameraView.cs
     文件        1588  2013-03-29 17:06  CameraLib\CameraView.Designer.cs
     文件        5814  2013-03-29 17:06  CameraLib\CameraView.resx
     文件        5051  2013-03-29 16:36  CameraLib\MyCamera.cs
     文件       26276  2013-04-04 01:00  CameraLib\MyCapture.cs
     目录           0  2013-04-10 18:26  CameraLib\obj\
     目录           0  2013-04-13 21:11  CameraLib\obj\Debug\
     文件         180  2013-04-13 21:11  CameraLib\obj\Debug\CameraLib.CameraView.resources
     文件        2792  2013-04-13 21:11  CameraLib\obj\Debug\CameraLib.csproj.FileListAbsolute.txt
     文件         779  2013-04-09 20:33  CameraLib\obj\Debug\CameraLib.csproj.GenerateResource.Cache
     文件       19968  2013-04-13 21:11  CameraLib\obj\Debug\CameraLib.dll
     文件       52736  2013-04-13 21:11  CameraLib\obj\Debug\CameraLib.pdb
     目录           0  2013-04-10 19:04  CameraLib\obj\Debug\Refactor\
     文件        8704  2013-04-10 19:04  CameraLib\obj\Debug\Refactor\CameraLib.dll
     文件        6463  2013-04-13 21:11  CameraLib\obj\Debug\ResolveAssemblyReference.cache
     目录           0  2013-03-29 16:36  CameraLib\obj\Debug\TempPE\
     目录           0  2013-04-10 18:26  CameraLib\obj\x86\
     目录           0  2013-04-10 18:26  CameraLib\obj\x86\Debug\
     文件         180  2013-04-03 16:49  CameraLib\obj\x86\Debug\CameraLib.CameraView.resources
............此处省略11个文件信息

评论

共有 条评论