ImageSize.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. Width = width;
  41. Height = height;
  42. MaxPixel = new Vector2D(width - 1, height - 1);
  43. }
  44. /// <summary>
  45. /// Computes an absolute point in the image.
  46. /// </summary>
  47. /// <param name="relativePoint">realtive point (x and y in [0,1])</param>
  48. /// <returns>absolute point</returns>
  49. public Vector2D getAbsolutePoint(Vector2D relativePoint) {
  50. return relativePoint.scale(MaxPixel);
  51. }
  52. /// <summary>
  53. /// Computes a relative point in the image.
  54. /// </summary>
  55. /// <param name="absolutePoint">absolute point in the image</param>
  56. /// <returns>realtive point (x and y in [0,1])</returns>
  57. public Vector2D getRelativePoint(Vector2D absolutePoint) {
  58. return new Vector2D(absolutePoint.X / Width, absolutePoint.Y / Height);
  59. }
  60. }
  61. }