我写了一个本地摄像头程序,想获得视频的二进制数据,并传到另一个控件上显示图像,以下是我的程序代码,到获得视频的二进制数据,并传到另一个控件上显示图像这里怎么也不会写了,求大虾们教教我啊
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using webcam;
namespace webcam
{
//Form1的摘要说明
public partial class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panelPreview;
private System.Windows.Forms.Button b_play;
private System.Windows.Forms.Button b_stop;
//必需的设计器变量
WebCamera wc;
public Form1()
{
//Windows窗体设计器支持所必需的
InitializeComponent();
//TODO:在InitializeComponent调用后添加任何构造函数代码
}
//清理所有正在使用的资源
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
//设计器支持所需的方法--不要使用代码编辑器修改
//此方法的内容。
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.b_play = new System.Windows.Forms.Button();
this.panelPreview = new System.Windows.Forms.Panel();
this.b_stop = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// b_play
//
this.b_play.Location = new System.Drawing.Point(280, 368);
this.b_play.Name = "b_play";
this.b_play.Size = new System.Drawing.Size(75, 23);
this.b_play.TabIndex = 0;
this.b_play.Text = "&Play";
this.b_play.Click += new System.EventHandler(this.b_start_Click);
//
// panelPreview
//
this.panelPreview.Location = new System.Drawing.Point(8, 8);
this.panelPreview.Name = "panelPreview";
this.panelPreview.Size = new System.Drawing.Size(344, 272);
this.panelPreview.TabIndex = 1;
//
// b_stop
//
this.b_stop.Enabled = false;
this.b_stop.Location = new System.Drawing.Point(360, 368);
this.b_stop.Name = "b_stop";
this.b_stop.Size = new System.Drawing.Size(75, 23);
this.b_stop.TabIndex = 2;
this.b_stop.Text = "&Stop";
this.b_stop.Click += new System.EventHandler(this.b_stop_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(134, 316);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(981, 413);
this.Controls.Add(this.label1);
this.Controls.Add(this.b_stop);
this.Controls.Add(this.panelPreview);
this.Controls.Add(this.b_play);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "GoodView test Web Camera";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); }
//应用程序的主入口点。
private void Form1_Load(object sender, System.EventArgs e)
{
b_play.Enabled = false;
b_stop.Enabled = true;
panelPreview.Size = new Size(330, 330);
wc = new WebCamera(panelPreview.Handle, panelPreview.Width, panelPreview.Height);
//wc.RecievedFrame+=new WebCamera.RecievedFrameEventHandler(wc_RecievedFrame);
wc.StartWebCam();
}
private void b_start_Click(object sender, System.EventArgs e)
{
b_play.Enabled = false;
b_stop.Enabled = true;
panelPreview.Size = new Size(330, 330);
wc = new WebCamera(panelPreview.Handle, panelPreview.Width, panelPreview.Height);
wc.StartWebCam();
}
private void b_stop_Click(object sender, System.EventArgs e)
{
b_play.Enabled = true;
b_stop.Enabled = false;
wc.CloseWebcam();
}
//private void wc_RecievedFrame(byte[] camdata)
//{
// label1.Text = DateTime.Now.ToString() + "测试数据" + camdata.Length.ToString();
// for (int i = 0; i < camdata.Length; i++)
// {
// this.textBox1.Text += camdata[i].ToString("X2") + " ";
// } // textBox1.Text = camdata.ToString();
//}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using webcam;
namespace webcam
{
//Form1的摘要说明
public partial class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panelPreview;
private System.Windows.Forms.Button b_play;
private System.Windows.Forms.Button b_stop;
//必需的设计器变量
WebCamera wc;
public Form1()
{
//Windows窗体设计器支持所必需的
InitializeComponent();
//TODO:在InitializeComponent调用后添加任何构造函数代码
}
//清理所有正在使用的资源
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
//设计器支持所需的方法--不要使用代码编辑器修改
//此方法的内容。
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.b_play = new System.Windows.Forms.Button();
this.panelPreview = new System.Windows.Forms.Panel();
this.b_stop = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// b_play
//
this.b_play.Location = new System.Drawing.Point(280, 368);
this.b_play.Name = "b_play";
this.b_play.Size = new System.Drawing.Size(75, 23);
this.b_play.TabIndex = 0;
this.b_play.Text = "&Play";
this.b_play.Click += new System.EventHandler(this.b_start_Click);
//
// panelPreview
//
this.panelPreview.Location = new System.Drawing.Point(8, 8);
this.panelPreview.Name = "panelPreview";
this.panelPreview.Size = new System.Drawing.Size(344, 272);
this.panelPreview.TabIndex = 1;
//
// b_stop
//
this.b_stop.Enabled = false;
this.b_stop.Location = new System.Drawing.Point(360, 368);
this.b_stop.Name = "b_stop";
this.b_stop.Size = new System.Drawing.Size(75, 23);
this.b_stop.TabIndex = 2;
this.b_stop.Text = "&Stop";
this.b_stop.Click += new System.EventHandler(this.b_stop_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(134, 316);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(981, 413);
this.Controls.Add(this.label1);
this.Controls.Add(this.b_stop);
this.Controls.Add(this.panelPreview);
this.Controls.Add(this.b_play);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "GoodView test Web Camera";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); }
//应用程序的主入口点。
private void Form1_Load(object sender, System.EventArgs e)
{
b_play.Enabled = false;
b_stop.Enabled = true;
panelPreview.Size = new Size(330, 330);
wc = new WebCamera(panelPreview.Handle, panelPreview.Width, panelPreview.Height);
//wc.RecievedFrame+=new WebCamera.RecievedFrameEventHandler(wc_RecievedFrame);
wc.StartWebCam();
}
private void b_start_Click(object sender, System.EventArgs e)
{
b_play.Enabled = false;
b_stop.Enabled = true;
panelPreview.Size = new Size(330, 330);
wc = new WebCamera(panelPreview.Handle, panelPreview.Width, panelPreview.Height);
wc.StartWebCam();
}
private void b_stop_Click(object sender, System.EventArgs e)
{
b_play.Enabled = true;
b_stop.Enabled = false;
wc.CloseWebcam();
}
//private void wc_RecievedFrame(byte[] camdata)
//{
// label1.Text = DateTime.Now.ToString() + "测试数据" + camdata.Length.ToString();
// for (int i = 0; i < camdata.Length; i++)
// {
// this.textBox1.Text += camdata[i].ToString("X2") + " ";
// } // textBox1.Text = camdata.ToString();
//}
}
}
好像要用directshow,编码解码的东西,音频视频哪有那么简单啊