Comments (9)
Hello.
You have to modify UsbCamera.cs a little.
Try these changes below and let me know it works fine or not.
Step1. Add this block around line 80.
public Action<Bitmap> BitmapCaptured
{
get { return CaptureGrabberCallback.Buffered; }
set { CaptureGrabberCallback.Buffered = value; }
}
private SampleGrabberCallback CaptureGrabberCallback;
Step2. Replace this block from
private Func<Bitmap> GetBitmapFromSampleGrabberCallback(DirectShow.ISampleGrabber i_grabber, int width, int height, int stride)
{
var sampler = new SampleGrabberCallback(width, height, stride);
i_grabber.SetCallback(sampler, 1); // WhichMethodToCallback = BufferCB
return () => sampler.GetBitmap();
}
to
private Func<Bitmap> GetBitmapFromSampleGrabberCallback(DirectShow.ISampleGrabber i_grabber, int width, int height, int stride)
{
CaptureGrabberCallback = new SampleGrabberCallback(width, height, stride);
i_grabber.SetCallback(CaptureGrabberCallback, 1); // WhichMethodToCallback = BufferCB
return () => CaptureGrabberCallback.GetBitmap();
}
Step3. subscribe BitmapCaptured.
camera.BitmapCaptured += (bmp) =>
{
// called here every frame captured.
};
from usbcamera.
good,thanks!it works very well.
from usbcamera.
it works,but it isn't thread-safe.
from usbcamera.
Could you show me the code that produce the problem?
from usbcamera.
like this:
camera.BitmapCaptured += (bmp) =>
{
this.textBox1.Text = "hello";
this.BackgroundImage = bmp;
};
You're better off implementing it with events
from usbcamera.
Are you saying that the line below cause InvalidOperationException? (Cross-thread operation not valid.)
this.textBox1.Text = "hello";
If so, it is your responsibility to call cross-thread control in a thread-safe way.
textBox1.Invoke((Action)(() =>
{
this.textBox1.Text = "hello";
}));
from usbcamera.
I did it.And it can work.But I have many controls to process.So I will do more work.It's not just convenient.
from usbcamera.
I use delegates to handle those controls, so I do a lot of things. Using Invoke is much easier.thanks!
from usbcamera.
Thank you for your response.
from usbcamera.
Related Issues (20)
- WPF 每次 BufferToBitmap 的时候都创建新的 WriteableBitmap 岂不是完全没发挥 WriteableBitmap 的性能 HOT 11
- Release taking long time sometimes HOT 1
- missing events HOT 4
- How can I switch camera? HOT 2
- provide nuget package HOT 4
- Implement IDisposable / IObservable pattern HOT 1
- 需要增加对于部分非标的虚拟摄像头的过滤(It is necessary to increase the filtering of some non-standard virtual cameras) HOT 7
- Problem with showing preview HOT 4
- Memory issues HOT 13
- How to distinguish the camera with the same name? HOT 4
- Add a feature to get plain image data as byte array to not call lock bits over and over again HOT 15
- threads in thread pool may be blocked by this library HOT 4
- Inconsistent Image Quality When Saving Still Capture Monochrome Sensor Data as BMP HOT 8
- Can't able to set brightness and exposure at run time when camera running on different thread HOT 2
- Capture Pin not working on all cameras HOT 3
- happens ArgumentException when I dispose PictureBox's old image. HOT 1
- How can I turn off the usbcamera lights? HOT 9
- why not working in 4K? HOT 6
- Add an IsReady method to see if we can get the image? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usbcamera.