示例#1
0
        private void On_TakeImageButtonClick(object sender, EventArgs e)
        {
            if (webCam != null)
            {
                if (stillImageBox.Image != null)
                {
                    stillImageBox.Image.Dispose();
                }
                if (originalPicture != null)
                {
                    originalPicture.Dispose();
                }
                try
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    // Release any previous buffer
                    if (ip != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(ip);
                        ip = IntPtr.Zero;
                    }
                    // capture image
                    ip = webCam.Click();
                    originalPicture = new System.Drawing.Bitmap(webCam.Width, webCam.Height, webCam.Stride, PixelFormat.Format24bppRgb, ip);
                    originalPicture.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

                    System.Drawing.Bitmap result = new System.Drawing.Bitmap(200, 150);
                    using (System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(result))
                    {
                        graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        graph.DrawImage(originalPicture, 0, 0, 200, 150);
                        System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Purple, 1);
                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                graph.DrawRectangle(pen, 25 + 25 - 10 + 50 * j, 25 - 10 + 50 * i, 20, 20);
                            }
                        }
                        pen.Dispose();
                    }
                    stillImageBox.Image = result;
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
                catch
                {
                    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(VIDEOWIDTH, VIDEOHEIGHT);
                    using (System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        System.Drawing.Rectangle size = new System.Drawing.Rectangle(0, 0, VIDEOWIDTH, VIDEOHEIGHT);
                        graph.FillRectangle(System.Drawing.Brushes.White, size);
                    }
                    stillImageBox.Image = bitmap;
                    webCam.Dispose();
                    webCam = null;
                }
            }
        }
 private void btnRefresh_Click(object sender, EventArgs e)
 {
     oWebCam.CloseConnection();
     oWebCam.Dispose();
     oWebCam           = new WebCamera();
     oWebCam.Container = pictureBox1;
     oWebCam.OpenConnection();
     Clipboard.Clear();
 }
示例#3
0
        private void DisconnectUSBCamera_Click(object sender, RoutedEventArgs e)
        {
            _videoViewerWpf.Stop();

            _webCamera.Stop();
            _webCamera.Dispose();

            _connector.Disconnect(_webCamera, _provider);
        }
示例#4
0
        private void On_TakeImageButtonClick(object sender, EventArgs e)
        {
            if (webCam != null)
            {
                if (stillImageBox.Image != null)
                {
                    stillImageBox.Image.Dispose();
                }
                try
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    // Release any previous buffer
                    if (ip != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(ip);
                        ip = IntPtr.Zero;
                    }
                    // capture image
                    ip = webCam.Click();
                    System.Drawing.Bitmap b = new System.Drawing.Bitmap(webCam.Width, webCam.Height, webCam.Stride, PixelFormat.Format24bppRgb, ip);
                    b.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
                    readedColors = rubiksColorReader.ReadRubiksSide(b, new Vector2((webCam.Width - webCam.Height) / 2 + webCam.Height / 6, webCam.Height / 6), webCam.Height / 3, webCam.Height / 12);

                    System.Drawing.Bitmap res = new System.Drawing.Bitmap(VIDEOWIDTH, VIDEOHEIGHT);

                    using (System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(res))
                    {
                        System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Purple, 1);
                        graph.DrawImage(b, 0, 0, 320, 240);
                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                graph.DrawRectangle(pen, 40 + 30 + 80 * j, 30 + 80 * i, 20, 20);
                            }
                        }
                        pen.Dispose();
                    }
                    b.Dispose();
                    stillImageBox.Image = res;
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
                catch
                {
                    readedColors = new Color[3, 3];
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            readedColors[i, j] = Color.White;
                        }
                    }
                    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(VIDEOWIDTH, VIDEOHEIGHT);
                    using (System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        System.Drawing.Rectangle size = new System.Drawing.Rectangle(0, 0, VIDEOWIDTH, VIDEOHEIGHT);
                        graph.FillRectangle(System.Drawing.Brushes.White, size);
                    }
                    stillImageBox.Image = bitmap;
                    webCam.Dispose();
                    webCam = null;
                    UpdateCameraDevices();
                }
                finally
                {
                    int k = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            rubiksReadedColors.SetColor(k, readedColors[j, i]);
                            k++;
                        }
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Changes the camera device.
        /// </summary>
        public void ChangeCamera(int deviceID)
        {
            if (!initialized)
            {
                return;
            }

            // same device
            if (WebCamera != null && WebCamera.DeviceID == deviceID)
            {
                return;
            }

            // find the proper info
            VideoDeviceInfo newDeviceInfo = null;

            foreach (var info in Cameras)
            {
                if (info.DeviceID != deviceID)
                {
                    continue;
                }

                newDeviceInfo = info;
                break;
            }

            if (newDeviceInfo == null)
            {
                return;
            }


            // begin change device
            bool capturing = false;

            if (WebCamera != null)
            {
                // disconnect
                if (LocalImageProvider != null)
                {
                    audioConnector.Disconnect(WebCamera, LocalImageProvider);
                }
                audioConnector.Disconnect(WebCamera, phoneCallVideoSender);

                // dispose previous device
                capturing = WebCamera.Capturing;
                WebCamera.Stop();
                WebCamera.Dispose();
            }

            // create new
            WebCamera = WebCamera.GetDevice(newDeviceInfo);

            if (WebCamera != null)
            {
                audioConnector.Connect(WebCamera, LocalImageProvider);
                audioConnector.Connect(WebCamera, phoneCallVideoSender);

                if (capturing)
                {
                    WebCamera.Start();
                }
            }

            OnPropertyChanged("WebCamera");
        }
示例#6
0
        public void Dispose()
        {
            // audio
            if (audioCollection != null)
            {
                audioCollection.Dispose();
            }

            if (audioConnector != null)
            {
                audioConnector.Dispose();
            }

            if (Microphone != null)
            {
                UnsubscribeFromMicrophoneEvents();
                Microphone.Dispose();
            }

            if (Speaker != null)
            {
                UnsubscribeFromSpeakerEvents();
                Speaker.Dispose();
            }

            if (wavRecorder != null)
            {
                wavRecorder.Dispose();
            }

            if (wavPlayer != null)
            {
                wavPlayer.Dispose();
            }

            if (mp3StreamPlayback != null)
            {
                mp3StreamPlayback.Dispose();
            }

            if (ringtonePlayer != null)
            {
                ringtonePlayer.Dispose();
            }

            if (ringbackPlayer != null)
            {
                ringbackPlayer.Dispose();
            }

            // video
            if (videoCollection != null)
            {
                videoCollection.Dispose();
            }

            if (videoConnector != null)
            {
                videoConnector.Dispose();
            }

            if (WebCamera != null)
            {
                WebCamera.Dispose();
            }
        }
        public void Dispose()
        {
            // audio
            if (_audioConnector != null)
            {
                _audioConnector.Dispose();
            }

            if (Microphone != null)
            {
                UnsubscribeFromMicrophoneEvents();
                Microphone.Dispose();
            }

            if (Speaker != null)
            {
                UnsubscribeFromSpeakerEvents();
                Speaker.Dispose();
            }

            if (_wavRecorder != null)
            {
                _wavRecorder.Dispose();
            }

            if (_wavPlayer != null)
            {
                _wavPlayer.Dispose();
            }

            if (_mp3StreamPlayback != null)
            {
                _mp3StreamPlayback.Dispose();
            }

            if (_ringtonePlayer != null)
            {
                _ringtonePlayer.Dispose();
            }

            if (_ringbackPlayer != null)
            {
                _ringbackPlayer.Dispose();
            }

            if (AudioEnhancer != null)
            {
                AudioEnhancer.Dispose();
            }

            if (_dtmfPlayer != null)
            {
                _dtmfPlayer.Dispose();
            }

            //if (outgoingDataMixer != null)
            //    outgoingDataMixer.Dispose();

            //if (speakerMixer != null)
            //    speakerMixer.Dispose();

            //if (recordDataMixer != null)
            //    recordDataMixer.Dispose();

            if (_phoneCallAudioSender != null)
            {
                _phoneCallAudioSender.Dispose();
            }

            if (_phoneCallAudioReceiver != null)
            {
                _phoneCallAudioReceiver.Dispose();
            }


            // video
            if (_videoConnector != null)
            {
                _videoConnector.Dispose();
            }

            if (WebCamera != null)
            {
                WebCamera.Dispose();
            }

            if (_phoneCallVideoReceiver != null)
            {
                _phoneCallVideoReceiver.Dispose();
            }

            if (_phoneCallVideoSender != null)
            {
                _phoneCallVideoSender.Dispose();
            }
        }