I have a cshtml page that takes an image as a string, and displays it in an image tag. Here's the code:
@model ReadModel
@{
ViewBag.Title = "Display";
ViewBag.Project = "IS";
Layout = null;
}
<body style="max-height:1100px; max-width:850px">
@if (Model.readImages.Count > 0)
{
//only images will hit this code. Other file types are written to the Response header in the controller
string imgSrc = String.Format("data:" + Model.readImages[0].contentType + ";base64,{0}", Model.readImages[0].imageString);
<img src="@imgSrc" style="max-height:1100px; max-width:850px"/>
}
else
{
<p>No Image to display</p>;
}
<p>@Model.error</p>
</body>
The problem is that in IE 11, if the image is large (it is failing with an 18 MB image) the page will just spin and spin until it eventually fails and just shows a white page. It works fine with regular sized images.
Now, as the comment mentions, if the file is not an image it displays by writing the byte array of the file to the response in the controller using C#, like so:
byte[] bytes = Convert.FromBase64String(imageModel.readImages[0].imageString);
Response.Clear();
Response.ContentType = imageModel.readImages[0].contentType;//"application/pdf";
Response.AddHeader("content-length", bytes.Length.ToString());
//write the reponse the browser
Response.BinaryWrite(bytes);
Response.AppendHeader("content-disposition", "inline; filename=" + imageModel.readImages[0].fileName);
Response.End();
This above C# code also works for displaying images, even really large ones, however one of the requirements I have is that the image must be able to print on a single page, hence the max-height and max-width attributes.
If I write the image using the C# code, the large images will print to 4 or 5 pages.
So what I need is either a way to make the tag work for large images, or have the C# code resize the image to fit on an 8.5 x 11 page.
I know that chrome handles these images just fine, unfortunately another requirement is to get it to work in IE.
Checking the "Use software rendering instead of GPU rendering" does not help.
Any ideas?