وب کم و C#.net ؟

bitaroos

Member
سلام دوستان

کسی کد نویسی ئه عکس گرفتن با وب کم رو تو c# بلده؟
(با کلیک روی یک دگمه عکس گرفته بشه و توی یک متغیر Bitmap ذخیره بشه)

سپاس فراوان
 

bitaroos

Member
سلام
فکر کنم این سایت کمکتون کنه
http://easywebcam.codeplex.com/

ممنون دوست عزیز

خیلی خوب بود فقط یه مشکل داشت.

من می خوام عکسها با ابعاد 800 * 600 پیکسل گرفته بشه ولی این کتابخونه ای که معرفی کردید حداکثر با ابعاد 640 * 480 پیکسل عکس رو میتونه بهمون بده.

اگر کتابخونه دیگه ای هم سراغ دارید، ممنون میشم معرفی کنید
 
با سلام شما می تونید از کلاسAVICap(موجود در فایلAVICap.dll)شامل رابط های متنی جهت دسترسی به سخت افزار ویدیو صوت است و قابلیت ضبطstreamویدیو را فراهم می کنه.
تنها عیبی که داره یکwin32APIهستش.
 
کد

امید وارم کمکت کنه:
کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace SecuritySystem_CS
{
    public partial class Form1 : Form
    {

        const int WM_CAP_START = 1024;
        const int WS_CHILD = 1073741824;
        const int WS_VISIBLE = 268435456;
        const int WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10);
        const int WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11);
        const int WM_CAP_EDIT_COPY = (WM_CAP_START + 30);
        const int WM_CAP_SEQUENCE = (WM_CAP_START + 62);
        const int WM_CAP_FILE_SAVEAS = (WM_CAP_START + 23);
        const int WM_CAP_SET_SCALE = (WM_CAP_START + 53);
        const int WM_CAP_SET_PREVIEWRATE = (WM_CAP_START + 52);
        const int WM_CAP_SET_PREVIEW = (WM_CAP_START + 50);
        const int SWP_NOMOVE = 2;
        const int SWP_NOSIZE = 1;
        const int SWP_NOZORDER = 4;
        const int HWND_BOTTOM = 1;
private int hWnd;

        [System.Runtime.InteropServices.DllImport("avicap32.dll")]
        static extern bool capGetDriverDescriptionA(short wDriverIndex, string lpszName, int cbName, string lpszVer, int cbVer);
        [System.Runtime.InteropServices.DllImport("avicap32.dll")]

        static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWnd, int nID);
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]

        static extern int SendMessage(int hwnd, int Msg, int wParam, [MarshalAs(UnmanagedType.AsAny)] 
object lParam);
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetWindowPos")]
        static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
        [System.Runtime.InteropServices.DllImport("user32")]
        static extern bool DestroyWindow(int hndw);
        private int hWnd;

        public Form1()
        {
            InitializeComponent();
        }

        private void PreviewVideo(PictureBox pbCtrl)
        {
            hWnd = capCreateCaptureWindowA("0", WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, pbCtrl.Handle.ToInt32(), 0);
            if (SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, 0, 0) != 0)
            {
                SendMessage(hWnd, WM_CAP_SET_SCALE, 1, 0);
                SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0);
                SendMessage(hWnd, WM_CAP_SET_PREVIEW, 1, 0);
                SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, pbCtrl.Width, pbCtrl.Height, SWP_NOMOVE | SWP_NOZORDER);
            }
            else
            {
                DestroyWindow(hWnd);
            }
        }

       
        

        private void btnStartRecording_Click(object sender, EventArgs e)
        {
            btnStartRecording.Enabled = false;
            btnStopRecording.Enabled = true;
            Application.DoEvents();
            SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0);
        }

        private void btnStopRecording_Click(object sender, EventArgs e)
        {
            btnStartRecording.Enabled = true;
            btnStopRecording.Enabled = false;
            Application.DoEvents();
            SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, "C:\\" + System.DateTime.Now.ToFileTime() + ".avi");            
        }

        private void btnTakeSnapshot_Click(object sender, EventArgs e)
        {
            IDataObject data;
            Image bmap;
            SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0);
            data = Clipboard.GetDataObject();
            if (data.GetDataPresent(typeof(System.Drawing.Bitmap)))
            {
                bmap = ((Image)(data.GetData(typeof(System.Drawing.Bitmap))));
                bmap.Save("C:\\" + System.DateTime.Now.ToFileTime() + ".bmp");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            PreviewVideo(PictureBox1);
        }
    }
}
 

ghasem110deh

New Member
خطا hWnd

امید وارم کمکت کنه:
کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace SecuritySystem_CS
{
    public partial class Form1 : Form
    {

        const int WM_CAP_START = 1024;
        const int WS_CHILD = 1073741824;
        const int WS_VISIBLE = 268435456;
        const int WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10);
        const int WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11);
        const int WM_CAP_EDIT_COPY = (WM_CAP_START + 30);
        const int WM_CAP_SEQUENCE = (WM_CAP_START + 62);
        const int WM_CAP_FILE_SAVEAS = (WM_CAP_START + 23);
        const int WM_CAP_SET_SCALE = (WM_CAP_START + 53);
        const int WM_CAP_SET_PREVIEWRATE = (WM_CAP_START + 52);
        const int WM_CAP_SET_PREVIEW = (WM_CAP_START + 50);
        const int SWP_NOMOVE = 2;
        const int SWP_NOSIZE = 1;
        const int SWP_NOZORDER = 4;
        const int HWND_BOTTOM = 1;
private int hWnd;

        [System.Runtime.InteropServices.DllImport("avicap32.dll")]
        static extern bool capGetDriverDescriptionA(short wDriverIndex, string lpszName, int cbName, string lpszVer, int cbVer);
        [System.Runtime.InteropServices.DllImport("avicap32.dll")]

        static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWnd, int nID);
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]

        static extern int SendMessage(int hwnd, int Msg, int wParam, [MarshalAs(UnmanagedType.AsAny)] 
object lParam);
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetWindowPos")]
        static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
        [System.Runtime.InteropServices.DllImport("user32")]
        static extern bool DestroyWindow(int hndw);
        private int hWnd;

        public Form1()
        {
            InitializeComponent();
        }

        private void PreviewVideo(PictureBox pbCtrl)
        {
            hWnd = capCreateCaptureWindowA("0", WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, pbCtrl.Handle.ToInt32(), 0);
            if (SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, 0, 0) != 0)
            {
                SendMessage(hWnd, WM_CAP_SET_SCALE, 1, 0);
                SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0);
                SendMessage(hWnd, WM_CAP_SET_PREVIEW, 1, 0);
                SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, pbCtrl.Width, pbCtrl.Height, SWP_NOMOVE | SWP_NOZORDER);
            }
            else
            {
                DestroyWindow(hWnd);
            }
        }

       
        

        private void btnStartRecording_Click(object sender, EventArgs e)
        {
            btnStartRecording.Enabled = false;
            btnStopRecording.Enabled = true;
            Application.DoEvents();
            SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0);
        }

        private void btnStopRecording_Click(object sender, EventArgs e)
        {
            btnStartRecording.Enabled = true;
            btnStopRecording.Enabled = false;
            Application.DoEvents();
            SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, "C:\\" + System.DateTime.Now.ToFileTime() + ".avi");            
        }

        private void btnTakeSnapshot_Click(object sender, EventArgs e)
        {
            IDataObject data;
            Image bmap;
            SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0);
            data = Clipboard.GetDataObject();
            if (data.GetDataPresent(typeof(System.Drawing.Bitmap)))
            {
                bmap = ((Image)(data.GetData(typeof(System.Drawing.Bitmap))));
                bmap.Save("C:\\" + System.DateTime.Now.ToFileTime() + ".bmp");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            PreviewVideo(PictureBox1);
        }
    }
}

سلام ... واسه من خطا میده ... زیر hWnd از private int hWnd خط قرمز میکشه ؟
 

جدیدترین ارسال ها

بالا