【发布时间】:2017-08-27 14:53:51
【问题描述】:
《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:原视频是黑白的,我得到的位图是正确的
【问题讨论】:
-
我不知道
25是干什么用的。但是,您可以尝试使用sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)。有关您的lpbi的尺寸信息,请参阅this question -
我已将您的解决方案移至社区 wiki 答案。
标签: c# bitmap ogre3d videotexture