/// <summary>Export a frame into a bitmap</summary>
        /// <param name="position">Position of the frame</param>
        public Bitmap GetBitmap(int position)
        {
            if (position > countFrames)
            {
                throw new Exception("Invalid frame position: " + position);
            }

            Avi.AVISTREAMINFO streamInfo = GetStreamInfo(StreamPointer);

            Avi.BITMAPINFO bih        = new Avi.BITMAPINFO();
            int            headerSize = Marshal.SizeOf(bih.bmiHeader);

            //Decompress the frame and return a pointer to the DIB
            int dib = Avi.AVIStreamGetFrame(getFrameObject, firstFrame + position);

            //Copy the bitmap header into a managed struct
            bih.bmiColors = this.palette;
            bih.bmiHeader = (Avi.BITMAPINFOHEADER)Marshal.PtrToStructure(new IntPtr(dib), bih.bmiHeader.GetType());

            if (bih.bmiHeader.biSizeImage < 1)
            {
                throw new Exception("Exception in VideoStreamGetFrame");
            }

            //copy the image
            int framePaletteSize = bih.bmiHeader.biClrUsed * Avi.RGBQUAD_SIZE;

            byte[] bitmapData = new byte[bih.bmiHeader.biSizeImage];
            IntPtr dibPointer = new IntPtr(dib + Marshal.SizeOf(bih.bmiHeader) + framePaletteSize);

            Marshal.Copy(dibPointer, bitmapData, 0, bih.bmiHeader.biSizeImage);

            //copy bitmap info
            byte[] bitmapInfo = new byte[Marshal.SizeOf(bih)];
            IntPtr ptr        = Marshal.AllocHGlobal(bitmapInfo.Length);

            Marshal.StructureToPtr(bih, ptr, false);
            Marshal.Copy(ptr, bitmapInfo, 0, bitmapInfo.Length);
            Marshal.FreeHGlobal(ptr);

            //create file header
            Avi.BITMAPFILEHEADER bfh = new Avi.BITMAPFILEHEADER();
            bfh.bfType      = Avi.BMP_MAGIC_COOKIE;
            bfh.bfSize      = (Int32)(55 + bih.bmiHeader.biSizeImage);        //size of file as written to disk
            bfh.bfReserved1 = 0;
            bfh.bfReserved2 = 0;
            bfh.bfOffBits   = Marshal.SizeOf(bih) + Marshal.SizeOf(bfh);
            if (bih.bmiHeader.biBitCount < 8)
            {
                //There is a palette between header and pixel data
                bfh.bfOffBits += bih.bmiHeader.biClrUsed * Avi.RGBQUAD_SIZE; //Avi.PALETTE_SIZE;
            }

            //write a bitmap stream
            BinaryWriter bw = new BinaryWriter(new MemoryStream());

            //write header
            bw.Write(bfh.bfType);
            bw.Write(bfh.bfSize);
            bw.Write(bfh.bfReserved1);
            bw.Write(bfh.bfReserved2);
            bw.Write(bfh.bfOffBits);
            //write bitmap info
            bw.Write(bitmapInfo);
            //write bitmap data
            bw.Write(bitmapData);

            Bitmap   bmp            = (Bitmap)Image.FromStream(bw.BaseStream);
            Bitmap   saveableBitmap = new Bitmap(bmp.Width, bmp.Height);
            Graphics g = Graphics.FromImage(saveableBitmap);

            g.DrawImage(bmp, 0, 0);
            g.Dispose();
            bmp.Dispose();

            bw.Close();
            return(saveableBitmap);
        }