3
我有幾個頁面顯示圖片,他們調用控制器的動作,其代碼顯示在[藝術post.problem是從碎紙加載的圖像,不加載的時刻,但首先顯示的文字,然後顯示圖像,我試過2負載的圖像,但同樣的效果更精確的方法......所以一個接一個的加載, 請你幫忙 當前代碼行動渲染圖像沒有1-1效果
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部分的代碼,然後調用動作 與渲染米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();
}
這解決了可能的問題Thenks –