IntptrRawImage.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. namespace VideoStatusInspectorCSLib
  3. {
  4. /// <summary>
  5. /// 数据区用指针表示的图像
  6. /// </summary>
  7. public class IntptrRawImage
  8. {
  9. private IntPtr _dataPointer;
  10. private int _width;
  11. private int _height;
  12. private readonly int _bytesPerPixel = 0;
  13. private readonly EnumColorType _colorType = EnumColorType.Gray8;
  14. /// <summary>
  15. /// 数据区首地址
  16. /// </summary>
  17. public IntPtr DataPointer { get => _dataPointer; }
  18. /// <summary>
  19. /// 图像宽度
  20. /// </summary>
  21. public int Width { get => _width; }
  22. /// <summary>
  23. /// 图像高度
  24. /// </summary>
  25. public int Height { get => _height; }
  26. /// <summary>
  27. /// 一个像素用几个Byte来表示
  28. /// 如:8位灰度图,则BytesPerPixel=1,24位RGB图像,则BytesPerPixel=3
  29. /// </summary>
  30. public int BytesPerPixel { get => _bytesPerPixel; }
  31. /// <summary>
  32. /// 图像的色彩类型
  33. /// </summary>
  34. public EnumColorType ColorType { get => _colorType; }
  35. /// <summary>
  36. /// 构造函数
  37. /// </summary>
  38. public IntptrRawImage(EnumColorType colorType = EnumColorType.Gray8)
  39. {
  40. _dataPointer = IntPtr.Zero;
  41. _width = 0;
  42. _height = 0;
  43. _colorType = colorType;
  44. int bytesPerPixel = RawImage.GetBytesPerPixel(colorType);
  45. _bytesPerPixel = bytesPerPixel;
  46. }
  47. /// <summary>
  48. /// 构造函数
  49. /// </summary>
  50. /// <param name="data"></param>
  51. /// <param name="width"></param>
  52. /// <param name="height"></param>
  53. /// <param name="channel"></param>
  54. public IntptrRawImage(IntPtr dataPointer, int width, int height, EnumColorType colorType)
  55. {
  56. _dataPointer = dataPointer;
  57. _width = width;
  58. _height = height;
  59. _colorType = colorType;
  60. int bytesPerPixel = RawImage.GetBytesPerPixel(colorType);
  61. _bytesPerPixel = bytesPerPixel;
  62. }
  63. }
  64. }