I have several pages that show pictures, they call controller action whose code is shown in [art of post.Problem is the image loaded from shredding, not load in moment but first display the text, and then display the image, I tried 2 more precise method for load images but the same effect … so one by one the loading,
please for your help
current code action
public FileContentResult ImageVew(string sourcePath)
{
string location = (string)Session["TicketFilePath"] + sourcePath;
byte[] myByte = System.IO.File.ReadAllBytes(location);
return File(myByte, "image/jpeg");
Image i;
using (MemoryStream ms = new MemoryStream())
{
ms.Write(myByte, 0, myByte.Length);
i = Image.FromStream(ms);
}
return File(imageToByteArray(i.GetThumbnailImage(100, 100, () => false, IntPtr.Zero)), "image/png");
}
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
Last version this method,but not result
public ActionResult ImageVew(string sourcePath)
{
FileInfo fi = new FileInfo((string)Session["TicketFilePath"] + sourcePath);
return File(fi.FullName, Utilities.MimeType(fi.Name));
}
public ActionResult ImageVew(string sourcePath)
{
FileInfo fi = new FileInfo((string)Session["TicketFilePath"] + sourcePath);
byte[] imageFile = System.IO.File.ReadAllBytes(fi.FullName);
return new FileContentResult(imageFile, Utilities.ImageType(fi.Name));
}
public ActionResult ImageVew(string sourcePath)
{
FileInfo fi = new FileInfo((string)Session["TicketFilePath"] + sourcePath);
if (fi.Exists)
{
byte[] imageFile = System.IO.File.ReadAllBytes(fi.FullName);
return File(imageFile, Utilities.ImageType(fi.Name));
}
else return null;
}
Image rendering 1 by 1 and image loading from network path…but after 1. loading image cashing ,and lad on moment
Please help me developer guys
Part f code then call action
with rendering m cotrol
private void WriteDataRow(Class item, HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderBeginTag(HtmlTextWriterTag.Center);
writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "20px");
string src = Url.Action("ImageVew", new { sourcePath = item.Status.Marker });
writer.AddAttribute(HtmlTextWriterAttribute.Src, src );
writer.AddAttribute(HtmlTextWriterAttribute.Alt, item.Status.StatusName);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
}
Asp.net mvc will never serve more than one request at the time from the same user (same session really) unless you turn of session state or make it read only for that action.
To the controller or the action you need to add
Now this won’t work with Cassini(built in webserver in visual studio) as it only serves a single request at time but if you test with IIS express or IIS you should see them load in parallell using the first method.