-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an IsReady method to see if we can get the image? #38
Comments
Hello. (1) about line 560. private class SampleGrabberCallback : DirectShow.ISampleGrabberCB
{
private byte[] Buffer;
private object BufferLock = new object();
public bool IsReady { get { return Buffer != null; } } <- Add this line. (2) about line 85. class UsbCamera
{
....
private Action Releasing;
private Action Released;
public bool IsReady { get { return Streams[StreamType.Capture].IsReady; } } <- Add this line. (3) about line 250. change code from GetBitmap = GetBitmapFromSampleGrabberCallback(sample.Grabber, sample.Width, sample.Height, sample.Stride);
Func<Bitmap> GetBitmapFromSampleGrabberCallback(DirectShow.ISampleGrabber grabber, int width, int height, int stride)
{
var sampler = new SampleGrabberCallback(grabber, width, height, stride, false);
return () => sampler.GetBitmap();
} to GetBitmap = GetBitmapFromSampleGrabberCallback(sample.Grabber, sample.Width, sample.Height, sample.Stride);
Func<Bitmap> GetBitmapFromSampleGrabberCallback(DirectShow.ISampleGrabber grabber, int width, int height, int stride)
{
Streams[StreamType.Capture] = new SampleGrabberCallback(grabber, width, height, stride, false);
return () => Streams[StreamType.Capture].GetBitmap();
} Then you can use IsReady property like this. var sw = System.Diagnostics.Stopwatch.StartNew();
while(camera.IsReady == false)
{
System.Threading.Thread.Sleep(10);
}
Console.WriteLine("sw:{0}", sw.ElapsedMilliseconds); Is this meets your request? |
Hi, thank you for replying, I will try it after I get home today. |
Yes, It works! That will make people (at least myself) a lot easier to get the photo as soon as possible.
|
For example:
The text was updated successfully, but these errors were encountered: