我正在尝试创建一个直接显示图来播放由 8 位灰度位图组成的视频。(使用directshow.net。)
我正在使用源过滤器和 vmr9 渲染器。
源过滤器的输出引脚使用以下代码定义:
bmi.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
bmi.Width = width;
bmi.Height = height;;
bmi.Planes = 1;
bmi.BitCount = (short)bitcount;
bmi.Compression = 0;
bmi.ImageSize = Math.Abs(bmi.Height) * bmi.Width * bmi.BitCount / 8;
bmi.ClrUsed = bmi.BitCount <= 8 ? 256 : 0;
bmi.ClrImportant = 0;
//bmi.XPelsPerMeter = 0;
//bmi.YPelsPerMeter = 0;
bool isGrayScale = bmi.BitCount <= 8 ? true : false;
int formatSize = Marshal.SizeOf(typeof(BitmapInfoHeader));
if (isGrayScale == true)
{
MessageWriter.Log.WriteTrace("Playback is grayscale.");
/// Color table holds an array of 256 RGBQAD values
/// Those are relevant only for grayscale bitmaps
formatSize += Marshal.SizeOf(typeof(RGBQUAD)) * bmi.ClrUsed;
}
IntPtr ptr = Marshal.AllocHGlobal(formatSize);
Marshal.StructureToPtr(bmi, ptr, false);
if (isGrayScale == true)
{
/// Adjust the pointer to the beginning of the
/// ColorTable address and create the grayscale color table
IntPtr ptrNext = (IntPtr)((int)ptr + Marshal.SizeOf(typeof(BitmapInfoHeader)));
for (int i = 0; i < bmi.ClrUsed; i++)
{
RGBQUAD rgbCell = new RGBQUAD();
rgbCell.rgbBlue = rgbCell.rgbGreen = rgbCell.rgbRed = (byte)i;
rgbCell.rgbReserved = 0;
Marshal.StructureToPtr(rgbCell, ptrNext, false);
ptrNext = (IntPtr)((int)ptrNext + Marshal.SizeOf(typeof(RGBQUAD)));
}
}
这会导致 Renderstream 返回“找不到中间过滤器的组合来建立连接”。
请帮忙!
谢谢。