标签:tps hosting head sage format public 响应 图片 ppa
/// <summary> /// 项目文件夹下路径 返回流类型数据,如:图片类型 /// </summary> /// <returns></returns> public HttpResponseMessage GetImg() { // ~/ ImageFile / 001.png //项目文件夹下路径 var imgPath = System.Web.Hosting.HostingEnvironment.MapPath("~/ImageFile/2.jpg"); // 从图片中读取byte var imgByte = File.ReadAllBytes(imgPath); // 从图片中读取流 var imgStream = new MemoryStream(File.ReadAllBytes(imgPath)); var resp = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(imgStream) //或者 // Content = new ByteArrayContent(imgByte) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); return resp; }
[HttpGet] public HttpResponseMessage SelectUploadFile() { Image img = Image.FromFile(@"C:\ImageFile\2.jpg"); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new ByteArrayContent(ms.ToArray()); result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); //设置http响应上的Content-Type 为image/Png媒体类型 return result; }
标签:tps hosting head sage format public 响应 图片 ppa
原文地址:https://www.cnblogs.com/Warmsunshine/p/9853560.html