急急急急--如何用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);
}
}

}

}
}
...全文
229 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-07-26
  • 打赏
  • 举报
回复
Multiselect = true;
foreach(string s in ofd.FileNames)
{
}
飞喵 2010-07-26
  • 打赏
  • 举报
回复
最好放在线程里循环发,选择图片那一步可以改成选择文件夹。

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧