You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.6 KiB

  1. //----------------------------------------------------------------------------
  2. // Copyright (C) 2004-2017 by EMGU Corporation. All rights reserved.
  3. //----------------------------------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. namespace Emgu.CV.UI
  8. {
  9. /// <summary>
  10. /// The Image viewer that display IImage
  11. /// </summary>
  12. public partial class ImageViewer : Form
  13. {
  14. /// <summary>
  15. /// Create an ImageViewer
  16. /// </summary>
  17. public ImageViewer()
  18. {
  19. InitializeComponent();
  20. }
  21. /// <summary>
  22. /// Create an ImageViewer from the specific <paramref name="image"/>
  23. /// </summary>
  24. /// <param name="image">The image to be displayed in this viewer</param>
  25. public ImageViewer(IImage image)
  26. : this()
  27. {
  28. if (image != null)
  29. {
  30. Size size = image.Size;
  31. size.Width += 12;
  32. size.Height += 38;
  33. if (!Size.Equals(size))
  34. Size = size;
  35. }
  36. Image = image;
  37. }
  38. /// <summary>
  39. /// Create an ImageViewer from the specific <paramref name="image"/>, using <paramref name="imageName"/> as window name
  40. /// </summary>
  41. /// <param name="image">The image to be displayed</param>
  42. /// <param name="imageName">The name of the image</param>
  43. public ImageViewer(IImage image, string imageName)
  44. : this(image)
  45. {
  46. Text = imageName;
  47. }
  48. /// <summary>
  49. /// Get or Set the image in this ImageViewer
  50. /// </summary>
  51. public IImage Image
  52. {
  53. get
  54. {
  55. return imageBox1.Image;
  56. }
  57. set
  58. {
  59. imageBox1.Image = value;
  60. }
  61. }
  62. /// <summary>
  63. /// Get the image box hosted in this viewer
  64. /// </summary>
  65. public ImageBox ImageBox
  66. {
  67. get
  68. {
  69. return imageBox1;
  70. }
  71. }
  72. /// <summary>
  73. /// Create a ImageViewer with the specific image and show it.
  74. /// </summary>
  75. /// <param name="image">The image to be displayed in ImageViewer</param>
  76. public static void Show(IImage image)
  77. {
  78. Application.Run(new ImageViewer(image));
  79. }
  80. /// <summary>
  81. /// Create a ImageViewer with the specific image and show it.
  82. /// </summary>
  83. /// <param name="image">The image to be displayed in ImageViewer</param>
  84. /// <param name="windowName">The name of the window</param>
  85. public static void Show(IImage image, String windowName)
  86. {
  87. Application.Run(new ImageViewer(image, windowName));
  88. }
  89. }
  90. }