private void ShowBitmap2(BitmapData bitmapData)
        {
            {
                if (bitmapData.DateTime != _currentShownTime || _redisplay)
                {
                    _redisplay = false;

                    // The following code does these functions:
                    //    Get a IntPtr to the start of the GBR bitmap
                    //    Transform via sample transformation (To be replaced with your C++ code)
                    //    Create a Bitmap with the result
                    //    Create a new Bitmap scaled to visible area on screen
                    //    Assign new Bitmap into PictureBox
                    //    Dispose first Bitmap
                    //
                    // The transformation is therefore done on the original image, but if the transformation is
                    // keeping to the same size, then this would be much more effective if the resize was done first,
                    // and the transformation afterwards.
                    // Scaling can be done by setting the Width and Height on the

                    int width  = bitmapData.GetPlaneWidth(0);
                    int height = bitmapData.GetPlaneHeight(0);
                    int stride = bitmapData.GetPlaneStride(0);

                    // When using RGB / BGR bitmaps, they have all bytes continues in memory.  The PlanePointer(0) is used for all planes:
                    IntPtr plane0 = bitmapData.GetPlanePointer(0);

                    //IntPtr newPlane0 = transform.Perform(plane0, width * height * 3);		// Make the sample transformation / color change
                    IntPtr newPlane0 = _transform.Perform(plane0, stride, width, height);                               // Make the sample transformation / color change

                    Image myImage = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, newPlane0);

                    if (pictureBox.Width != 0 && pictureBox.Height != 0)                        // Ignore when window is not visible
                    {
                        // We need to resize to the displayed area
                        pictureBox.Image = new Bitmap(myImage, pictureBox.Width, pictureBox.Height);

                        myImage.Dispose();
                        // ---- bitmapData.Dispose();  Need to be disposed on the calling thread
                        _transform.Release(newPlane0);

                        //textBoxTime.Text = bitmapData.DateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss.fff");
                    }
                }

                _currentShownTime = bitmapData.DateTime;
                Debug.WriteLine("Image time: " + bitmapData.DateTime.ToLocalTime().ToString("HH.mm.ss.fff") + ", Mode=" + _mode);
            }
            _requestInProgress = false;
        }
Пример #2
0
        void BitmapLiveSourceLiveContentEvent(object sender, EventArgs e)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    // Make sure we execute on the UI thread before updating UI Controls
                    BeginInvoke(new EventHandler(BitmapLiveSourceLiveContentEvent), new[] { sender, e });
                }
                else
                {
                    LiveContentEventArgs args = e as LiveContentEventArgs;
                    if (args != null)
                    {
                        if (args.LiveContent != null)
                        {
                            LiveSourceBitmapContent bitmapContent = args.LiveContent as LiveSourceBitmapContent;
                            if (bitmapContent != null)
                            {
                                labelCount.Text = "" + (_counter++);
                                if (_stopped)
                                {
                                    bitmapContent.Dispose();
                                }
                                else
                                {
                                    // The following code does these functions:
                                    //    Get a IntPtr to the start of the GBR bitmap
                                    //    Transform via sample transformation (To be replaced with your C++ code)
                                    //    Create a Bitmap with the result
                                    //    Create a new Bitmap scaled to visible area on screen
                                    //    Assign new Bitmap into PictureBox
                                    //    Dispose first Bitmap
                                    //
                                    // The transformation is therefore done on the original image, but if the transformation is
                                    // keeping to the same size, then this would be much more effective if the resize was done first,
                                    // and the transformation afterwards.
                                    // Scaling can be done by setting the Width and Height on the

                                    int width  = bitmapContent.GetPlaneWidth(0);
                                    int height = bitmapContent.GetPlaneHeight(0);
                                    int stride = bitmapContent.GetPlaneStride(0);

                                    // When using RGB / BGR bitmaps, they have all bytes continues in memory.  The PlanePointer(0) is used for all planes:
                                    IntPtr plane0 = bitmapContent.GetPlanePointer(0);

                                    IntPtr newPlane0 = transform.Perform(plane0, stride, width, height);                                                // Make the sample transformation / color change

                                    Image myImage = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, newPlane0);

                                    // We need to resize to the displayed area
                                    pictureBoxEnhanced.Image = new Bitmap(myImage, pictureBoxEnhanced.Width, pictureBoxEnhanced.Height);

                                    myImage.Dispose();
                                    bitmapContent.Dispose();
                                    transform.Release(newPlane0);
                                }
                            }
                        }
                        else if (args.Exception != null)
                        {
                            // Handle any exceptions occurred inside toolkit or on the communication to the VMS

                            Bitmap   bitmap = new Bitmap(320, 240);
                            Graphics g      = Graphics.FromImage(bitmap);
                            g.FillRectangle(Brushes.Black, 0, 0, bitmap.Width, bitmap.Height);
                            if (args.Exception is CommunicationMIPException)
                            {
                                g.DrawString("Connection lost to server ...", new Font(FontFamily.GenericMonospace, 12),
                                             Brushes.White, new PointF(20, pictureBoxEnhanced.Height / 2 - 20));
                            }
                            else
                            {
                                g.DrawString(args.Exception.Message, new Font(FontFamily.GenericMonospace, 12),
                                             Brushes.White, new PointF(20, pictureBoxEnhanced.Height / 2 - 20));
                            }
                            g.Dispose();
                            pictureBoxEnhanced.Image = new Bitmap(bitmap, pictureBoxEnhanced.Size);
                            bitmap.Dispose();
                        }
                    }
                }
            } catch (Exception ex)
            {
                EnvironmentManager.Instance.ExceptionDialog("BitmapLiveSourceLiveContentEvent", ex);
            }
        }
Пример #3
0
        private void ShowBitmap2(BitmapData bitmapData)
        {
            {
                if (bitmapData.DateTime != _currentShownTime || _redisplay)
                {
                    _redisplay = false;

                    // The following code does these functions:
                    //    Get a IntPtr to the start of the GBR bitmap
                    //    Transform via sample transformation (To be replaced with your C++ code)
                    //    Create a Bitmap with the result
                    //    Create a new Bitmap scaled to visible area on screen
                    //    Assign new Bitmap into PictureBox
                    //    Dispose first Bitmap
                    //
                    // The transformation is therefore done on the original image, but if the transformation is
                    // keeping to the same size, then this would be much more effective if the resize was done first,
                    // and the transformation afterwards.
                    // Scaling can be done by setting the Width and Height on the

                    int width  = bitmapData.GetPlaneWidth(0);
                    int height = bitmapData.GetPlaneHeight(0);
                    int stride = bitmapData.GetPlaneStride(0);

                    // When using RGB / BGR bitmaps, they have all bytes continues in memory.  The PlanePointer(0) is used for all planes:
                    IntPtr plane0 = bitmapData.GetPlanePointer(0);

                    IntPtr newPlane0 = transform.Perform(plane0, stride, width, height);                                // Make the sample transformation / color change

                    Image myImage = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, newPlane0);

                    // We need to resize to the displayed area
                    pictureBox.Image = new Bitmap(myImage, pictureBox.Width, pictureBox.Height);

                    myImage.Dispose();
                    // ---- bitmapData.Dispose();
                    transform.Release(newPlane0);

                    textBoxTime.Text = bitmapData.DateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss.fff");

                    // Inform the PlybackController of the time information - so skipping can be done correctly

                    //Update 2016
                    EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.PlaybackTimeInformation,
                                                                                                   new PlaybackTimeInformationData()
                    {
                        Item = _selectedItem.FQID, CurrentTime = bitmapData.DateTime, PreviousTime = bitmapData.PreviousDateTime, NextTime = bitmapData.NextDateTime
                    }));

                    if (_mode == PlaybackPlayModeData.Stop)
                    {
                        //Update 2016
                        EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.PlaybackCommand,
                                                                                                       new PlaybackCommandData()
                        {
                            Command = PlaybackData.Goto, DateTime = bitmapData.DateTime
                        }));
                    }
                    _currentShownTime = bitmapData.DateTime;
                    Debug.WriteLine("Image time: " + bitmapData.DateTime.ToLocalTime().ToString("HH.mm.ss.fff") + ", Mode=" + _mode);
                }
                _requestInProgress = false;
            }
        }