SmoothingModeGraphics.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. namespace Microsoft.Drawing
  4. {
  5. /// <summary>
  6. /// 暂时修改绘图对象的平滑模式,释放时改为原来模式
  7. /// </summary>
  8. public sealed class SmoothingModeGraphics : DisposableMini
  9. {
  10. private SmoothingMode m_OldMode; //原始的平滑模式
  11. private Graphics m_Graphics; //要修改平滑模式的绘图对象
  12. /// <summary>
  13. /// 构造函数,暂时修改为抗锯齿
  14. /// </summary>
  15. /// <param name="graphics">绘图对象</param>
  16. public SmoothingModeGraphics(Graphics graphics)
  17. : this(graphics, SmoothingMode.AntiAlias)
  18. {
  19. }
  20. /// <summary>
  21. /// 构造函数
  22. /// </summary>
  23. /// <param name="graphics">绘图对象</param>
  24. /// <param name="newMode">新平滑模式</param>
  25. public SmoothingModeGraphics(Graphics graphics, SmoothingMode newMode)
  26. {
  27. this.m_Graphics = graphics;
  28. this.m_OldMode = graphics.SmoothingMode;
  29. graphics.SmoothingMode = newMode;
  30. }
  31. /// <summary>
  32. /// 释放资源
  33. /// </summary>
  34. /// <param name="disposing">释放托管资源为true,否则为false</param>
  35. protected override void Dispose(bool disposing)
  36. {
  37. if (this.m_Graphics != null)
  38. {
  39. this.m_Graphics.SmoothingMode = this.m_OldMode;
  40. this.m_Graphics = null;
  41. }
  42. this.m_OldMode = SmoothingMode.Default;
  43. }
  44. }
  45. }