在 c/s 程序中 怎么实现图片的上传能力,就好比QQ那样上传自定义头像的,当选定了后 有一个控件显示你所选的图片,再把选定的图片存起来
请问怎么实现,谢谢
有例子更好([email protected]) 感激不尽
请问怎么实现,谢谢
有例子更好([email protected]) 感激不尽
解决方案 »
- 为什么我的datagridview一绑定就变格式?
- 【求助】排除数组重复[帮顶给分]
- 大家好,能帮我看看我的设计存在的缺陷吗?
- Winform中,在两个TreeView控件之间进行拖放操作,如何使得拖到目标TreeView时能自动高亮显示鼠标移过的节点?
- C#中两个泛型的值如何比较大小呢?
- winform 中的DataGrid 可以添加checkbox吗?在线等,急用
- 我想让用户可以自己设定datagrid列的显示顺序,可以将某列提前和退后,请问怎么实现?
- 请问既然Ilist已经继承了ICollection,为何CollectionBase类仍然要同时继承这2个接口?
- C#中Form窗体中的comboBox控件如何加载绑定文本文件数据?
- 百思不得其解的问题!在WINFORM中,我关闭窗口为何如此慢?
- VS2003是不是不支持ADO.net
- 关于 enableEventValidation=”true” 的问题
保存 也很容易啊
或者,
把它转化为二制制文件,保存在数据库中,也可以,保存图片地址.
服务器端:
//新建监听
TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8880); //开始监听
listener.Start();
while (true)
{
const int bufferSize = 4096;
TcpClient client = listener.AcceptTcpClient(); //接收客户端传过来的数据
NetworkStream clientStream = client.GetStream();
byte[] responseBuffer = new byte[bufferSize];
MemoryStream memStream = new MemoryStream();
int bytesRead = 0;
do
{
bytesRead = clientStream.Read(responseBuffer, 0, bufferSize);
memStream.Write(responseBuffer, 0, bytesRead); } while (bytesRead > 0);
StreamReader reader = new StreamReader(memStream);
FileStream fs = new FileStream("d:\\wrar370sc.exe", FileMode.OpenOrCreate);
BinaryWriter w = new BinaryWriter(fs);
w.Write(memStream.ToArray());
MessageBox.Show("成功");
fs.Close(); }
客户端:
TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("127.0.0.1"), 8880);
NetworkStream clientStream = client.GetStream();//创建接收用的Stream
byte[] data = File.ReadAllBytes("E:\\软件备份\\dreamweaver8chs\\Macromedia Dreamweaver v8.0 简体中文版\\Dreamweaver8-chs.exe");
clientStream.Write(data, 0, data.Length);
clientStream.Close();
client.Close();
如果要是上传到图片控件里就直接写到控件就可以了。
public void UploadImage(Byte[] bytContent, string account,string path)
{
if (!File.Exists("~/images/" + account + ".jpg")//判断在原来的文件夹里是否有同名的照片,文件夹在目录下
{
using (FileStream fs = File.Create(path + account + ".jpg"))
{
fs.Write(bytContent, 0, bytContent.Length);
}
}
}
只是上传的方法,根据穿进的三个参数,分别是FileUpload控件的名称,你想为这张照片命名的名称,存放的相对路径