public class ImageServiceController : ApiController { public HttpResponseMessage Get(string id) { try { var result = new HttpResponseMessage(HttpStatusCode.OK); String[] strArray = id.Split(','); int[] intArray = new int[strArray.Length]; for (int i = 0; i < strArray.Length; i++) { intArray[i] = int.Parse(strArray[i]); String filePath = HostingEnvironment.MapPath("~/Images/" + intArray[i] + ".png"); FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate); Image image = Image.FromStream(fileStream); MemoryStream memoryStream = new MemoryStream(); image.Save(memoryStream, ImageFormat.Png); result.Content = new ByteArrayContent(memoryStream.ToArray()); result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); fileStream.Close(); memoryStream.Dispose(); } return result; } catch (Exception ex) { return new HttpResponseMessage(HttpStatusCode.NotFound); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)