ImageSize.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace bbiwarg.Utility
  8. {
  9. /// <summary>
  10. /// Manages the size of a image.
  11. /// </summary>
  12. public class ImageSize
  13. {
  14. /// <summary>
  15. /// image width
  16. /// </summary>
  17. public int Width { get; private set; }
  18. /// <summary>
  19. /// image height
  20. /// </summary>
  21. public int Height { get; private set; }
  22. /// <summary>
  23. /// position in the image with maximum x and y values
  24. /// </summary>
  25. public Vector2D MaxPixel { get; private set; }
  26. /// <summary>
  27. /// the length of the longer image diagonal
  28. /// </summary>
  29. public float DiagonalLength { get { return MaxPixel.Length; } }
  30. /// <summary>
  31. /// number of pixels in the image
  32. /// </summary>
  33. public int NumPixels { get { return Width * Height; } }
  34. /// <summary>
  35. /// Constructs a ImageSize.
  36. /// </summary>
  37. /// <param name="width">image width</param>
  38. /// <param name="height">image height</param>
  39. public ImageSize(int width, int height)
  40. {
  41. Width = width;
  42. Height = height;
  43. MaxPixel = new Vector2D(width - 1, height - 1);
  44. }
  45. /// <summary>
  46. /// Computes an absolute point in the image.
  47. /// </summary>
  48. /// <param name="relativePoint">realtive point (x and y in [0,1])</param>
  49. /// <returns>absolute point</returns>
  50. public Vector2D getAbsolutePoint(Vector2D relativePoint)
  51. {
  52. return relativePoint.scale(MaxPixel);
  53. }
  54. /// <summary>
  55. /// Computes a relative point in the image.
  56. /// </summary>
  57. /// <param name="absolutePoint">absolute point in the image</param>
  58. /// <returns>realtive point (x and y in [0,1])</returns>
  59. public Vector2D getRelativePoint(Vector2D absolutePoint)
  60. {
  61. return new Vector2D(absolutePoint.X / Width, absolutePoint.Y / Height);
  62. }
  63. }
  64. }