SizeEx.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Drawing;
  2. namespace Microsoft.Drawing
  3. {
  4. /// <summary>
  5. /// Size 操作
  6. /// </summary>
  7. public static class SizeEx
  8. {
  9. /// <summary>
  10. /// 调整大小非空,影响原来大小
  11. /// </summary>
  12. /// <param name="size">要调整的大小</param>
  13. public static void MakeNotEmpty(ref Size size)
  14. {
  15. if (size.Width < 1)
  16. size.Width = 1;
  17. if (size.Height < 1)
  18. size.Height = 1;
  19. }
  20. /// <summary>
  21. /// 宽度放大倍数
  22. /// </summary>
  23. /// <param name="size">Size</param>
  24. /// <param name="count">倍数</param>
  25. /// <returns>新的Size</returns>
  26. public static Size MultiplyWidth(Size size, int count)
  27. {
  28. return new Size(size.Width * count, size.Height);
  29. }
  30. /// <summary>
  31. /// 高度放大倍数
  32. /// </summary>
  33. /// <param name="size">Size</param>
  34. /// <param name="count">倍数</param>
  35. /// <returns>新的Size</returns>
  36. public static Size MultiplyHeight(Size size, int count)
  37. {
  38. return new Size(size.Width, size.Height * count);
  39. }
  40. /// <summary>
  41. /// 宽度和高度放大倍数
  42. /// </summary>
  43. /// <param name="size">Size</param>
  44. /// <param name="count">倍数</param>
  45. /// <returns>新的Size</returns>
  46. public static Size MultiplyBoth(Size size, int count)
  47. {
  48. return new Size(size.Width * count, size.Height * count);
  49. }
  50. }
  51. }