0

There is a code in "OGRE 3D 1.7 Application Development Cookbook" like this:

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();

Why did the lpbi plus the biSize of lpbi and also plus 25? Because i want to convert the code into the C#, i almost finished, the texture rendered is green not the original color that the video has. like this:

Here is my c# code:

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: The original video is black and white and the bitmap i get is correct

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I don't know what's the `25` is used for. However, you can try to use `sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)`. See [this question](https://stackoverflow.com/questions/25713117/what-is-the-difference-between-bisizeimage-bisize-and-bfsize) about size info of your `lpbi` – pergy Aug 29 '17 at 12:35
  • I moved your solution to a community wiki answer. – Cœur Mar 06 '18 at 16:01

1 Answers1

1

Solution by OP.

The right code:

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++;
Cœur
  • 37,241
  • 25
  • 195
  • 267