我有几个显示图片的页面,他们调用 Controller Action ,其代码显示在[art of post.问题是从粉碎中加载的图像,瞬间加载不出来而是先显示文本,然后显示图像,我尝试了 2 种更精确的加载图像方法,但效果相同......所以一个一个地加载, 请帮忙 当前代码操作
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();
}
此方法的最新版本,但不是结果
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;
}
图像渲染 1 对 1 并从网络路径加载图像...但是在 1. 加载图像兑现之后,立即加载 请开发人员帮助我
f部分代码然后调用action 带渲染控制
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 永远不会同时处理来自同一用户(实际上是同一 session )的多个请求,除非您关闭 session 状态或将其设为只读以执行该操作。
到你需要添加的 Controller 或 Action
[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
现在这不适用于 Cassini(内置在 visual studio 中的网络服务器),因为它一次仅服务于单个请求,但如果您使用 IIS express 或 IIS 进行测试,您应该看到它们使用第一种方法并行加载。
关于c# - 渲染没有 1-1 效果的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12295609/