Asked — Edited
Resolved Resolved by DJ Sures!

(Tutorial 48) Change To Capture From A Picturebox

Hi Dj,

If I wanted to change the capture method from the entire screen to only what was in a picturebox, it looks like I would only need to change bmpScreenShot to point to my pictureBox, but when I ran it only one create a blank video (no errors) and for testing in the form load I set the value of pictureBox1 like this:


pictureBox1.ImageLocation = @"C:\Users\weyou_000\Pictures\test.jpg";

This is the section of code I'm looking at.


try {

        _frameCnt++;

        //Bitmap bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

        Bitmap bmpScreenShot = new Bitmap(pictureBox1.Bounds.Width, pictureBox1.Bounds.Height);

        using (Graphics gfxScreenShot = Graphics.FromImage(bmpScreenShot)) {

          gfxScreenShot.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

          gfxScreenShot.DrawImageUnscaled(Properties.Resources.Cursor, Cursor.Position);
        }

        _writer.WriteVideoFrame(bmpScreenShot);

        bmpScreenShot.Dispose();

        Invokers.SetText(lblTime, string.Format("{0} (frame: {1}, skipped: {2})", DateTime.Now.Subtract(_startTime), _frameCnt, _skipCnt));
      } finally {

        _frameSkip = false;
      }
    }


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

#2  

I'm still looking for some advice to this question.

PRO
Synthiam
#3  

You can do this...


try {

        _frameCnt++;

        _writer.WriteVideoFrame((bitmap)picturebox1.image);

        Invokers.SetText(lblTime, string.Format("{0} (frame: {1}, skipped: {2})", DateTime.Now.Subtract(_startTime), _frameCnt, _skipCnt));
      } finally {

        _frameSkip = false;
      }
    }

PRO
Synthiam
#5  

Just remember that loading the picture box with image data from a file is slow and not thread safe.