ImageReader.ashx.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Drawing.Imaging;
  6. using System.Reflection;
  7. using EMIS.Utility;
  8. namespace EMIS.Web.Controls.Handler
  9. {
  10. /// <summary>
  11. /// ImageReader 的摘要说明
  12. /// </summary>
  13. public class ImageReader : IHttpHandler
  14. {
  15. public void ProcessRequest(HttpContext context)
  16. {
  17. var image = RSI.Get(context.Request["key"]);
  18. context.Response.Buffer = true;
  19. context.Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
  20. context.Response.Expires = 0;
  21. context.Response.CacheControl = "no-cache";
  22. context.Response.AppendHeader("Pragma", "No-Cache");
  23. image.Save(context.Response.OutputStream, image.RawFormat);
  24. Type imageFormatType = typeof(ImageFormat);
  25. System.Reflection.PropertyInfo[] _ImageFormatList = imageFormatType.GetProperties(BindingFlags.Static | BindingFlags.Public);
  26. for (int i = 0; i != _ImageFormatList.Length; i++)
  27. {
  28. ImageFormat _FormatClass = (ImageFormat)_ImageFormatList[i].GetValue(null, null);
  29. if (_FormatClass.Guid.Equals(image.RawFormat.Guid))
  30. {
  31. context.Response.ContentType = "image/" + _ImageFormatList[i].Name.ToLower();
  32. }
  33. }
  34. context.Response.End();
  35. }
  36. public bool IsReusable
  37. {
  38. get
  39. {
  40. return false;
  41. }
  42. }
  43. }
  44. }