Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
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:

Code:


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


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

Code:


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;
}
}

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
#2  
I'm still looking for some advice to this question.
PRO
Synthiam
#3  
You can do this...

Code:


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.