/// <summary>Prepare for decompressing frames</summary> /// <remarks> /// This method has to be called before GetBitmap and ExportBitmap. /// Release ressources with GetFrameClose. /// </remarks> public void GetFrameOpen() { Avi.AVISTREAMINFO streamInfo = GetStreamInfo(StreamPointer); //Open frames Avi.BITMAPINFOHEADER bih = new Avi.BITMAPINFOHEADER(); bih.biBitCount = countBitsPerPixel; bih.biClrImportant = 0; bih.biClrUsed = 0; bih.biCompression = 0; bih.biPlanes = 1; bih.biSize = Marshal.SizeOf(bih); bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; // Corrections by M. Covington: // If these are pre-set, interlaced video is not handled correctly. // Better to give zeroes and let Windows fill them in. bih.biHeight = 0; // was (Int32)streamInfo.rcFrame.bottom; bih.biWidth = 0; // was (Int32)streamInfo.rcFrame.right; // Corrections by M. Covington: // Validate the bit count, because some AVI files give a bit count // that is not one of the allowed values in a BitmapInfoHeader. // Here 0 means for Windows to figure it out from other information. if (bih.biBitCount > 24) { bih.biBitCount = 32; } else if (bih.biBitCount > 16) { bih.biBitCount = 24; } else if (bih.biBitCount > 8) { bih.biBitCount = 16; } else if (bih.biBitCount > 4) { bih.biBitCount = 8; } else if (bih.biBitCount > 0) { bih.biBitCount = 4; } getFrameObject = Avi.AVIStreamGetFrameOpen(StreamPointer, ref bih); if (getFrameObject == 0) { throw new Exception("Exception in VideoStreamGetFrameOpen!"); } }