0

I have a panel in my winform which plays a video on selection,and while the video is playing i need to grab the frames from it, which is after a button click,And the frames grabbed should be saved with a file name .I did a lot of research on implementing this ,

Initially i was trying for screenshot capture functions for that specific panel and displaying it in a picurebox. 1."copyfromscreen()" 2.using system messages. 3.drawtobitmap() -control specific , all these didn't work out that well,and I was not satisfied with the result.

And later i realised there is a method in directshow Ibasicvideo.getcurrentimage() to grab the current frame from the rendering video.I have been searching the internet for a good working example , but didn't succeed,I really need help on this ,

Any solution to display the current image of the video inside a seperate picturebox is appreciable.Thanks in advance !!!!

Coding active
  • 1,620
  • 3
  • 23
  • 40

1 Answers1

1

Take a look at VMR9Snapper sample using a link from this post: take picture from webcam c#

int hr = windowlessCtrl.GetCurrentImage(out currentImage);
DsError.ThrowExceptionForHR(hr);

if (currentImage != IntPtr.Zero)
{
  BitmapInfoHeader structure = new BitmapInfoHeader();
  Marshal.PtrToStructure(currentImage, structure);

  bmp = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, new IntPtr(currentImage.ToInt64() + 40));
  bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

  if (saveFileDialog.ShowDialog() == DialogResult.OK)
  {
    bmp.Save(saveFileDialog.FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);
  }
}
Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158