首页 新闻 会员 周边

用流上传图片后 图片大小改变 不清楚原因

0
悬赏园豆:20 [待解决问题]

我先拿到图片后转成byte[]数组 然后把byte[] 通过流保存在别的路径下  可是发现多大的图片 保存进去 大小都变成了128KB 百度不到原因 求大神  此为保存方法

public static string SaveImages(byte[] imgFile, string savepath)
        {
            MemoryStream ms = null;
            FileStream fs = null;
            string allpath = HttpContext.Current.Server.MapPath(savepath);


            ms = new MemoryStream(imgFile);
            fs = new FileStream(allpath, FileMode.OpenOrCreate);
            ms.WriteTo(fs);
            string root = System.Configuration.ConfigurationSettings.AppSettings["ImageSite"].ToString();
            string picPathRes = root + savepath.Replace("~", "");
            ms.Close();
            fs.Close();
            ms = null;
            fs = null;
            return picPathRes;
        }
甄宇的主页 甄宇 | 初学一级 | 园豆:2
提问于:2014-11-24 16:51
< >
分享
所有回答(3)
0

 试试  File.WriteAllBytes

xmj112288 | 园豆:126 (初学一级) | 2014-11-24 16:59
0

检查下服务器上传大小限制,防火墙限制,路由器限制。。。反正就是某个东西在限制。

XiaoFaye | 园豆:3087 (老鸟四级) | 2014-11-24 17:23
0
Stream output = null;//这里构建一个输出文件流,也就是打开一个文件 byte[] buffer = new byte[4096];
int read = 0;
Stream responeStream = res.GetResponseStream(); 
while((read = responseStream.Read(buffer, 0, buffer.Length)) > 0)
 { 
        output.Write(buffer, 0, read);
 }

可以试试这个方法,你可以把buffer设置大一点!

Mr.Brian | 园豆:1518 (小虾三级) | 2014-11-25 09:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册