为什么不使用Microsoft® Video for Windows® (VFW)
解决方案 »
- c#如何批量产生ColumnHeader
- 2个List之间的拷贝 ListA = ListB
- 关于媒体播放的
- 散分了,
- 關于關閉窗口的問題! winForm
- RichTextBox的内容传到另一个窗体,如何传,要含字体格式?
- 请问到哪里下载directshow.net?
- 求解决C#中字符串格式问题!
- 求助! 如何将SQL里存储(Image字段)的图片取出来放到Image服务器控件内呢??在线等~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 最难的.NET程序员面试问题
- DevExpress.XtraGrid.GridControl 显示图片列 不是从数据库读取 而是一个path 或者image
- C#如何统计当前目录中的文件个数
学习
pb.loction=new point(24;58);
pb.size=new size(100,200);
pb.image=imagelist1.images[0];
this.control.add(pb);//pb.image=imagelist1.images[0];
这句总是提示错误说索引值无效。
请教 如何应用才能显示图片呢?
/// 视频按钮功能,打开当前已安装的视频驱动程序,并向远程客户端发送信息,通知视频连接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tool_Video_Click(object sender, EventArgs e)
{
viodeo = new Video(pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height); //创建并引用Video类
viodeo.StartWebCam(); //打开视频设备
ClassMsg msg = new ClassMsg();
msg.sendKind = SendKind.SendCommand;
msg.msgCommand = MsgCommand.VideoOpen;
msg.Data = Encoding.Unicode.GetBytes("");
IPAddress ip = IPAddress.Parse(((this.Tag as TreeNode).Tag as ClassUserInfo).userIp);
string port = Convert.ToString(((this.Tag as TreeNode).Tag as ClassUserInfo).userPort);
udpsocket.Send(ip,Convert.ToInt32(port),new ClassSerializers().SerializeBinary(msg).ToArray());
Voiding = true;
SendViod = false;
timer1.Enabled = true;
panel7.Visible = true;
} /// <summary>
/// 以每秒级的速度向远程客户端发送图片,并将图片存储在远程客户端的指定路劲下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
if(Voiding || !SendViod || pictureBox1.Image != null)
{
SendViod = true; //视频开启或关闭
IPAddress ip = IPAddress.Parse(((this.Tag as TreeNode).Tag as ClassUserInfo).userIp);
string port = Convert.ToString(((this.Tag as TreeNode).Tag as ClassUserInfo).userPort);
////string msgid = Guid.NewGuid().ToString(); //设置全局唯一标识
string revid = ((this.Tag as TreeNode).Tag as ClassUserInfo).userID; //远程用户ID
string sid = Publec_Class.UserID; //当前用户ID ClassMsg msg = new ClassMsg();
msg.sendKind = SendKind.SendCommand; //信息发送的类型
msg.msgCommand = MsgCommand.Videoing; //发送视频中
msg.sendState = SendState.Sending; //文件正在发送中
msg.SID = sid;
msg.SIP = msg.GetLocalIP();
msg.RID = revid;
//msg.msgID = msgid;
msg.Data = Encoding.Unicode.GetBytes(""); ClassMsg start = new ClassMsg();
start.sendKind = SendKind.SendCommand; //信息发送的类型
start.msgCommand = MsgCommand.Videoing; //发送视频中
start.sendState = SendState.Start; //文件正在发送中
start.SID = sid;
start.SIP = msg.GetLocalIP();
start.RID = revid;
//start.msgID = msgid;
start.Data = Encoding.Unicode.GetBytes("");
udpsocket.Send(ip,Convert.ToInt32(port),new ClassSerializers().SerializeBinary(start).ToArray()); viodeo.GrabImage(pictureBox1.Handle,"C:\\TempVoid.Bmp"); //将pictureBox1中的图片存入到指定的路径中
FileStream stream = File.OpenRead("C:\\TempVoid.Bmp"); //打开已有的文件,以便读取
//对stream中的文件进行分流发送
int sendlen = 1024; //设置读取块的大小
long sunlen = (stream.Length); //获取文件的总大小
int offest = 0; //读取文件的起始位置
while(sunlen > 0)
{
if (sunlen < sendlen)
sendlen = Convert.ToInt32(sunlen);
byte[] msgdata = new byte[sendlen];
stream.Read(msgdata,offest,sendlen);
msg.sendState = SendState.Sending;
msg.Data = msgdata;
udpsocket.Send(ip,Convert.ToInt32(port),new ClassSerializers().SerializeBinary(msg).ToArray());
sunlen -= sendlen;
} ClassMsg End = new ClassMsg();
End.sendKind = SendKind.SendCommand; //信息发送的类型
End.msgCommand = MsgCommand.VideoClose; //发送视频中
End.sendState = SendState.End; //文件发送结束
End.SID = sid;
End.SIP = msg.GetLocalIP();
End.RID = revid;
//End.msgID = msgid;
End.Data = Encoding.Unicode.GetBytes("");
stream.Close();
udpsocket.Send(ip, Convert.ToInt32(port), new ClassSerializers().SerializeBinary(start).ToArray());
SendViod = false;
}
} /// <summary>
/// 套接字托管
/// </summary>
public delegate void DataArrivalDelegate(byte[] Data, IPAddress Ip, int Port);
private void udpSocket1_DataArrival(byte[] Data, IPAddress Ip, int Port)
{
DataArrivalDelegate outDelegate = new DataArrivalDelegate(DataArrival);
this.BeginInvoke(outDelegate, new object[] {Data,Ip,Port});
}
private void DataArrival(byte[] Data, IPAddress Ip, int Port)
{
try
{
ClassMsg msg = new ClassSerializers().DeSerializeBinary(new MemoryStream(Data)) as ClassMsg;
switch(msg.msgCommand)
{
//打开视频
case MsgCommand.VideoOpen:
Voiding = true;
SendViod = false;
timer1.Enabled = true;
panel7.Visible = true;
break;
//正在视频中
case MsgCommand.Videoing:
GetVoid(Data, Ip, Port);
break;
//关闭视频
case MsgCommand.VideoClose:
Voiding = false;
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
} /// <summary>
/// 接收图片存入到指定的路劲下,并将图片显示在pictureBox2上
/// </summary>
private void GetVoid(byte[] Data, IPAddress Ip, int Port)
{
ClassMsg msg = (ClassMsg)new ClassSerializers().DeSerializeBinary(new MemoryStream(Data));
string sid = msg.SID;
string msgid = msg.msgID;
switch(msg.msgCommand) //信息的命令
{
//正在视频中
case MsgCommand.Videoing:
{
switch(msg.sendState) // 信息的状态
{
//开始发送视频文件
case SendState.Start:
{
FileStream fs = null;
try
{
string FileName = "C:\\Void.bmp"; //设置文件路径
fs = File.Create(FileName);
fs.Write(msg.Data,0,msg.Data.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
fs.Close();
}
}
break;
//正在发送视频文件
case SendState.Sending:
{
FileStream fs = null;
try
{
string FileName = "C:\\Void.bmp";
fs = File.OpenWrite(FileName);
fs.Seek(0, SeekOrigin.End); //将该流的当前位置设为0
fs.Write(msg.Data, 0, msg.Data.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
fs.Close();
}
}
break;
//发送视频文件结束
case SendState.End:
{
pictureBox2.Load("C:\\Void.bmp");
}
break;
}
}
break;
}
} private void button_Incepl_Click(object sender, EventArgs e)
{
Voiding = false;
SendViod = true;
timer1.Enabled = false;
panel7.Visible = false;
viodeo.CloseWebcam();
string dir = System.Environment.CurrentDirectory;
dir = dir.Substring(0, dir.Length - 9);
pictureBox1.Load(@"E:\程序\C# 项目开发\MyQQ\MyQQClient\Images\ChatImages\QQ08.jpg");
pictureBox2.Load(@"E:\程序\C# 项目开发\MyQQ\MyQQClient\Images\ChatImages\QQ12.jpg");
}