急急急急--如何用c#编写一个连续发送图片的程序
华为黑名单 2010-07-26 08:29:20 我这里有一段代码是发送图片的代码,我想如何修改一下就可以连续的发图了;我的代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using SerializeObj;
namespace fjsc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
byte[] arrbyte = null;
OpenFileDialog ofd = null;
private SerializeFile myMedia = new SerializeFile();
private void button1_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
ofd.Multiselect = false;
ofd.InitialDirectory = "D:\\";
ofd.Filter = "files (*.JPG)|*.JPG|All files (*.*)|*.*";
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = ofd.FileName;
//this.pictureBox1.Image = Image.FromFile(ofd.FileName);
try
{
FileInfo EzoneFile = new FileInfo(ofd.FileName);
myMedia.FileName = EzoneFile.Name;
myMedia.FileType = System.IO.Path.GetExtension(ofd.FileName);
myMedia.LoadFileData(ofd.OpenFile());
//this.textBox1.Text = myMedia.FileName;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (myMedia.FileName != "")
{
try
{
TcpClient client = new TcpClient();
client.Connect(System.Net.IPAddress.Parse("166.111.64.37"), 8880);
NetworkStream clientStream = client.GetStream();//创建接收用的Stream
//FileStream myFile = new FileStream(XmlUrl, FileMode.Create);
MemoryStream myFile = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(myFile, myMedia);
arrbyte = myFile.ToArray();
myFile.Close();
clientStream.Write(arrbyte, 0, arrbyte.Length);
clientStream.Close();
client.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}