因为之前写的代码,也能获取到图片流信息,但是会是凌乱的线条,后百度得这个方法,必须记录一下
C#
try { WebRequest myrequest = WebRequest.Create(HttpContext.Current.Request["path"]);//前台js传的path,可以是远程服务器上的,也可以是本地的 WebResponse myresponse = myrequest.GetResponse(); Stream imgstream = myresponse.GetResponseStream(); System.Drawing.Image img = System.Drawing.Image.FromStream(imgstream); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.AddHeader("Content-Length", ms.Length.ToString()); context.Response.Clear(); context.Response.ContentType = "image/jpeg"; context.Response.BinaryWrite(ms.ToArray()); context.Response.OutputStream.Flush(); context.Response.OutputStream.Close(); } catch (Exception ex) { log.Error("读取图片异常:", ex); throw ex; }
远程获取图片文件流的方法
十分感谢脚本之家:http://www.jb51.net/article/78993.htm