public static Bitmap GetBitmap(string FileName, double time) { try { Interop.qedit.MediaDetClass md = new Interop.qedit.MediaDetClass(); md.Filename = FileName; md.CurrentStream = 0; Interop.qedit._AMMediaType mt = md.StreamMediaType; VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mt.pbFormat, typeof(VideoInfoHeader)); int width = vih.BmiHeader.Width; int height = vih.BmiHeader.Height; IntPtr bufPtr = IntPtr.Zero; int bufSize = 0; // call once to get the buffer size needed md.GetBitmapBits(0.0, ref bufSize, bufPtr, width, height); //allocate memory bufPtr = Marshal.AllocHGlobal(bufSize); // call to retrieve the dib if (time <= md.StreamLength) { md.GetBitmapBits(time, ref bufSize, bufPtr, width, height); } else { md.GetBitmapBits(0.0, ref bufSize, bufPtr, width, height); } // create a bitmap object; 40 is the size of the header on a 32-bit machine Bitmap result = new Bitmap(width, height, width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, new IntPtr((int)bufPtr + 40)); result.RotateFlip(RotateFlipType.Rotate180FlipX); //System.Runtime.InteropServices.Marshal.FreeHGlobal(bufPtr); return(result); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } return(null); }
public static Bitmap GetBitmap(string FileName, double time) { try { Interop.qedit.MediaDetClass md = new Interop.qedit.MediaDetClass(); md.Filename = FileName; md.CurrentStream = 0; Interop.qedit._AMMediaType mt = md.StreamMediaType; VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure( mt.pbFormat, typeof(VideoInfoHeader) ); int width = vih.BmiHeader.Width; int height = vih.BmiHeader.Height; IntPtr bufPtr = IntPtr.Zero; int bufSize = 0; // call once to get the buffer size needed md.GetBitmapBits( 0.0, ref bufSize, bufPtr, width, height ); //allocate memory bufPtr = Marshal.AllocHGlobal( bufSize ); // call to retrieve the dib if(time <= md.StreamLength) md.GetBitmapBits( time, ref bufSize, bufPtr, width, height); else md.GetBitmapBits( 0.0, ref bufSize, bufPtr, width, height); // create a bitmap object; 40 is the size of the header on a 32-bit machine Bitmap result = new Bitmap( width, height, width*3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, new IntPtr( (int)bufPtr + 40 )); result.RotateFlip( RotateFlipType.Rotate180FlipX ); //System.Runtime.InteropServices.Marshal.FreeHGlobal(bufPtr); return result; } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } return null; }