如何在 Ogre3d 中正确地将数据提供给 Hardwarepixelbuffer?

How to give data to Hardwarepixelbuffer correctly in Ogre3d?

"OGRE 3D 1.7 Application Development Cookbook"中有这样一段代码:

m_VideoTexture->m_PixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
memcpy(m_VideoTexture->m_PixelBuffer->getCurrentLock().data, lpbi + lpbi->biSize + 25, lpbi->biSizeImage);
m_VideoTexture->m_PixelBuffer->unlock();

为什么lpbi加上lpbi的biSize还要加上25?因为我想将代码转换为 C#,所以我几乎完成了,呈现的纹理是绿色,而不是视频的原始颜色。 像这样:

这是我的 C# 代码:

System.Drawing.Bitmap bitmap = videotexMgr.Stream.GetBitmap(videotex.FrameNum);
        MemoryStream ms = new MemoryStream();
        bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        byte[] bitmapBuffer = new byte[ms.Length];
        ms.Seek(0, SeekOrigin.Begin);
        ms.Read(bitmapBuffer, 0, bitmapBuffer.Length);
        ms.Close();

        videotexMgr.PixelBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
        Marshal.Copy(bitmapBuffer, 0, videotex.PixelBuffer.CurrentLock.data, bitmapBuffer.Length);
        videotexMgr.PixelBuffer.Unlock();

PS: 原视频是黑白的,我得到的位图是正确的

OP 的解决方案。

正确的代码:

System.Drawing.Bitmap bitmap = videotex.Stream.GetBitmap(videotex.FrameNum);
bitmap.Save("./Media/materials/textures/xx.png");
Image image = new Image();
image.Load("xx.png", "General");
image.FlipAroundX();
videotexMgr.PixelBuffer.BlitFromMemory(image.GetPixelBox());
image.Dispose();

videotexMgr.FrameNum++;