123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- namespace VideoStatusInspectorCSLib
- {
- /// <summary>
- /// 数据区用指针表示的图像
- /// </summary>
- public class IntptrRawImage
- {
- private IntPtr _dataPointer;
- private int _width;
- private int _height;
- private readonly int _bytesPerPixel = 0;
- private readonly EnumColorType _colorType = EnumColorType.Gray8;
- /// <summary>
- /// 数据区首地址
- /// </summary>
- public IntPtr DataPointer { get => _dataPointer; }
- /// <summary>
- /// 图像宽度
- /// </summary>
- public int Width { get => _width; }
- /// <summary>
- /// 图像高度
- /// </summary>
- public int Height { get => _height; }
- /// <summary>
- /// 一个像素用几个Byte来表示
- /// 如:8位灰度图,则BytesPerPixel=1,24位RGB图像,则BytesPerPixel=3
- /// </summary>
- public int BytesPerPixel { get => _bytesPerPixel; }
- /// <summary>
- /// 图像的色彩类型
- /// </summary>
- public EnumColorType ColorType { get => _colorType; }
- /// <summary>
- /// 构造函数
- /// </summary>
- public IntptrRawImage(EnumColorType colorType = EnumColorType.Gray8)
- {
- _dataPointer = IntPtr.Zero;
- _width = 0;
- _height = 0;
- _colorType = colorType;
- int bytesPerPixel = RawImage.GetBytesPerPixel(colorType);
- _bytesPerPixel = bytesPerPixel;
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="data"></param>
- /// <param name="width"></param>
- /// <param name="height"></param>
- /// <param name="channel"></param>
- public IntptrRawImage(IntPtr dataPointer, int width, int height, EnumColorType colorType)
- {
- _dataPointer = dataPointer;
- _width = width;
- _height = height;
- _colorType = colorType;
- int bytesPerPixel = RawImage.GetBytesPerPixel(colorType);
- _bytesPerPixel = bytesPerPixel;
- }
- }
- }
|