谁能帮我分析一下这段代码大概讲的是什么意思?AVI视频格式分割里面的对象转换,大谢,对象转换的那段代码解释下就可以,其他的结构体不用
[StructLayout(LayoutKind.Sequential, Pack = 1)] struct BITMAPFILEHEADER
{
public ushort bfType;
public uint bfSize;
public ushort bfReserved1;
public ushort bfReserved2;
public uint bfOffBits;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
public const int BI_RGB = 0;
}
const uint DIB_RGB_COLORS = 0;
const uint DIB_PAL_COLORS = 1;
/**//// <summary>
/// 对象转换
/// </summary>
/// <param name="pBITMAPINFOHEADER"></param>
/// <returns></returns>
public static Bitmap ToBitmap(IntPtr pBITMAPINFOHEADER)
{
unsafe
{
BITMAPINFOHEADER* pbmi = (BITMAPINFOHEADER*)pBITMAPINFOHEADER;
BITMAPFILEHEADER pbmfi;
pbmfi.bfType = (int)'M' << 8 | (int)'B';
pbmfi.bfOffBits = (uint)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));
pbmfi.bfSize = pbmfi.bfOffBits + pbmi->biSizeImage;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
byte[] data = new byte[sizeof(BITMAPFILEHEADER)];
Marshal.Copy((IntPtr)(&pbmfi), data, 0, data.Length);
bw.Write(data);
data = new byte[sizeof(BITMAPINFOHEADER)];
Marshal.Copy(pBITMAPINFOHEADER, data, 0, data.Length);
bw.Write(data);
data = new byte[pbmi->biSizeImage];
++pbmi;
Marshal.Copy((IntPtr)pbmi, data, 0, data.Length);
bw.Write(data);
bw.Flush();
bw.BaseStream.Position = 0;
return new Bitmap(bw.BaseStream);
}
}
能加一个注释最好不过,谢谢