Форум

ip камера

Цитировать

Пример реализации библиотеки ozeki. На её основе показан краткий пример позаимствованного кода .

Создаем проект и добавляем ссылку на саму библиотеку.

using System;
using System.Windows.Forms;
using Ozeki.Camera;
using Ozeki.Camera.Data;
using Ozeki.Media.MediaHandlers;
using Ozeki.Media.MediaHandlers.Video;
using Ozeki.Media.Video.Controls;
Цитировать

Далее создаем поля

private OzekiCamera _camera;
        private CameraURLBuilderWF _myCameraUrlBuilder;
        private DrawingImageProvider _imageProvider;
        private MediaConnector _connector;
        private Speaker _speaker;
и инициализируем переменные в конструкторе

public Form1()
        {
            InitializeComponent();
 
            _myCameraUrlBuilder = new CameraURLBuilderWF();
            _connector = new MediaConnector();
            _imageProvider = new DrawingImageProvider();
            _speaker = Speaker.GetDefaultDevice();
 
            videoViewerWF1.SetImageProvider(_imageProvider);
        }
 
Цитировать

Далее  описываем логику событий кнопок

 private void btn_Compose_Click(object sender, EventArgs e)
        {
            var result = _myCameraUrlBuilder.ShowDialog();
 
            if (result != DialogResult.OK)
                return;
 
            tb_CameraURL.Text = _myCameraUrlBuilder.CameraURL;
 
            btn_Connect.Enabled = true;
        }
 
        private void btn_Connect_Click(object sender, EventArgs e)
        {
            if (_camera != null)
            {
                videoViewerWF1.Stop();
                _camera.Disconnect();
                _connector.Disconnect(_camera.VideoChannel, _imageProvider);
                _connector.Disconnect(_camera.AudioChannel, _speaker);
            }
 
            btn_Connect.Enabled = false;
 
            _camera = new OzekiCamera(_myCameraUrlBuilder.CameraURL);
 
            _camera.CameraStateChanged += _camera_CameraStateChanged;
 
            _connector.Connect(_camera.AudioChannel, _speaker);
            _connector.Connect(_camera.VideoChannel, _imageProvider);
            _camera.Start();
            if (_speaker != null)
                _speaker.Start();
 
            videoViewerWF1.Start();
        }
 
        void _camera_CameraStateChanged(object sender, CameraStateEventArgs e)
        {
            InvokeGuiThread(() =>
            {
                switch (e.State)
                {
                    case CameraState.Streaming:
                        btn_Disconnect.Enabled = true;
                        break;
                    case CameraState.Disconnected:
                        btn_Disconnect.Enabled = false;
                        btn_Connect.Enabled = true;
                        break;
                }
            });
        }
 
        private void InvokeGuiThread(Action action)
        {
            BeginInvoke(action);
        }
 
        private void btn_Disconnect_Click(object sender, EventArgs e)
        {
            videoViewerWF1.Stop();
            _camera.Disconnect();
            _speaker.Stop();
            _connector.Disconnect(_camera.VideoChannel, _imageProvider);
            _connector.Disconnect(_camera.AudioChannel, _speaker);
        }
Цитировать

И вариант самой winform

ip камера