Exemplo n.º 1
0
    public override async Task StartAsync(CancellationToken cancellationToken)
    {
        try
        {
            string[] devices = WindowsCapture.FindDevices();
            if (devices.Length == 0)
            {
                ErrorOccurred?.Invoke(this, new NotSupportedException("Could not open camera."));
            }

            WindowsCapture.VideoFormat[] formats = WindowsCapture.GetVideoFormat(DefaultCameraId);

            Decoder = new();
            Camera  = new(DefaultCameraId, formats[0]);
Exemplo n.º 2
0
        void DoStuff()
        {
            var image = this.FindControl <Image>("Preview");

            // [How to use]
            // check USB camera is available.
            string[] devices = WindowsCapture.FindDevices();
            if (devices.Length == 0)
            {
                return;                      // no camera.
            }
            // check format.
            int cameraIndex = 0;

            WindowsCapture.VideoFormat[] formats = WindowsCapture.GetVideoFormat(cameraIndex);
            for (int i = 0; i < formats.Length; i++)
            {
                Console.WriteLine("{0}:{1}", i, formats[i]);
            }

            // create usb camera and start.
            var camera = new WindowsCapture(cameraIndex, formats[0]);

            camera.Start();

            // get image.
            // Immediately after starting the USB camera,
            // GetBitmap() fails because image buffer is not prepared yet.
            var bmp = camera.GetBitmap();

            //// show image in PictureBox.
            var timer = new System.Timers.Timer(100);

            timer.Elapsed += (s, ev) =>
            {
                Dispatcher.UIThread.InvokeAsync(() =>
                {
                    if (image is not null)
                    {
                        image.Source = camera.GetBitmap();
                    }
                });
            };

            timer.Start();
        }
Exemplo n.º 3
0
    public override async Task StartAsync(CancellationToken cancellationToken)
    {
        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            throw new InvalidOperationException("OS not supported.");
        }

        try
        {
            string[] devices = WindowsCapture.FindDevices();
            if (devices.Length == 0)
            {
                ErrorOccurred?.Invoke(this, new NotSupportedException("Could not open camera."));
            }

            WindowsCapture.VideoFormat[] formats = WindowsCapture.GetVideoFormat(DefaultCameraId);

            Decoder = new();
            Camera  = new(DefaultCameraId, formats[0]);