标题:谁能帮我分析一下这段代码大概讲的是什么意思?AVI视频格式分割里面的对象转 ...
取消只看楼主
lianjiecuowu
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:152
专家分:107
注 册:2011-5-20
结帖率:85.71%
 问题点数:0 回复次数:0 
谁能帮我分析一下这段代码大概讲的是什么意思?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);
                       }
                   }





能加一个注释最好不过,谢谢
搜索更多相关主题的帖子: 分割 public 结构体 
2013-03-17 15:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-401103-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.325166 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved