我有几个显示图片的页面,它们调用控制器动作,其代码显示在[post的艺术加载图像的精确方法但效果相同......所以一一加载,请为您提供帮助当前代码操作
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 部分代码然后调用带有渲染 m 控制的操作
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();
}