/ Published in: C#
MVC action method to stream an image from the server and display it in the view
Expand |
Embed | Plain Text
//action to actually fetch the image [HttpGet] public ActionResult ShowImage() { byte[] image; var contentType = "image/png"; //get the image image = GetImageFromServer(@"..\Content\example.tif"); //convert from tiff to png Bitmap.FromStream(tiffStream).Save(pngStream, ImageFormat.Png); //return result { ImageStream = pngStream, MimeType = "image/png", Cacheability = HttpCacheability.NoCache }; } //get the image from the server (relative path) public byte[] GetImageFromServer(string name) { { stream.CopyTo(memoryStream); return memoryStream.ToArray(); } } //this is how to use it in your view to get the image <img src="@Url.Action("ShowImage","Home")">
You need to login to post a comment.
