//输出图片
public static void OutPutImg(string imgFilePath)
{
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(imgFilePath), FileMode.Open, FileAccess.Read);
DateTime contentModified = System.IO.File.GetLastWriteTime(HttpContext.Current.Server.MapPath(imgFilePath));
if (IsClientCached(contentModified))
{
HttpContext.Current.Response.StatusCode = 304;
HttpContext.Current.Response.SuppressContent = true;
}
else
{
byte[] mydata = new byte[fs.Length];
int Length = Convert.ToInt32(fs.Length);
fs.Read(mydata, 0, Length);
fs.Close();
HttpContext.Current.Response.OutputStream.Write(mydata, 0, Length);
HttpContext.Current.Response.ContentType = "image/jpeg";
HttpContext.Current.Response.End();
HttpContext.Current.Response.Cache.SetETagFromFileDependencies();
HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(true);
HttpContext.Current.Response.Cache.SetLastModified(contentModified);
}
}
复制代码 代码如下: