Exemplo n.º 1
0
        /// <summary>
        /// Override of PopulateSample to fill in the sample data
        /// </summary>
        /// <param name="ip">Pointer to the buffer to fill</param>
        /// <param name="iSize">Size of the buffer</param>
        /// <param name="iRead">Returns the number of buffer bytes used</param>
        /// <returns>HRESULT for failure, S_Ok for success, or S_False for end of stream</returns>
        override protected int PopulateSample(IntPtr ip, int iSize, out int iRead)
        {
            int hr = S_Ok;

            // Send back MAXFRAMES frames, then end the stream
            if (m_rtSampleTime < m_rtStopTime)
            {
                // It is *much* easier to draw in a Format32bppArgb buffer than a YUYV buffer.  So,
                // we draw in ARGB, and translate to the appropriate format.

                Graphics g;
                float    sLeft;
                float    sTop;
                SizeF    d;

                // The string to print
                string sString = DateTime.Now.ToString("h:mm:ss");
                sString = m_iFrameNumber.ToString();

                // Get a graphics handle.  We do the drawing on an ARGB32 bitmap, then
                // convert the bitmap to the appropriate format (below)
                g = Graphics.FromImage(m_bitmapOverlay);

                try
                {
                    // Clear the entire box to transparent
                    g.Clear(Color.Transparent);

                    // Prepare to put the specified string on the image
                    g.DrawRectangle(Pens.Blue, 0, 0, m_Width - 1, m_Height - 1);
                    g.DrawRectangle(Pens.Blue, 1, 1, m_Width - 3, m_Height - 3);

                    // Print the string in the box
                    d = g.MeasureString(sString, m_fontOverlay);

                    sLeft = (m_Width - d.Width) / 2;
                    sTop  = (m_Height - d.Height) / 2;

                    g.DrawString(sString, m_fontOverlay, Brushes.Red, sLeft, sTop, StringFormat.GenericTypographic);
                }
                finally
                {
                    g.Dispose();
                }

                // Convert the RGB bitmap to the appropriate format
                iRead = ConvertImage.ToFormat((int)m_SubType, m_Width, m_Height, m_Stride, m_pData, ip);
                Debug.Assert(iRead <= iSize);
            }
            else
            {
                hr    = S_False; // End of stream
                iRead = 0;
            }

            return(hr);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override of PopulateSample to fill in the sample data
        /// </summary>
        /// <param name="ip">Pointer to the buffer to fill</param>
        /// <param name="iSize">Size of the buffer</param>
        /// <param name="iRead">Returns the number of buffer bytes used</param>
        /// <returns>HRESULT for failure, S_Ok for success, or S_False for end of stream</returns>
        override protected int PopulateSample(IntPtr ip, int iSize, out int iRead)
        {
            int hr = S_Ok;

            // Send back MAXFRAMES frames, then end the stream
            if (m_rtSampleTime < m_rtStopTime)
            {
                // It is *much* easier to draw in a Format32bppArgb buffer than a YUYV, NV12, etc buffer.  So,
                // we draw in ARGB, then translate it to the appropriate format.

                Graphics  g;
                Rectangle r1 = new Rectangle(0, 0, m_Width - 1, m_Height - 1);

                // Get a graphics handle.
                g = Graphics.FromImage(m_bitmapOverlay);

                try
                {
                    // Clear the entire box to the specified color
                    g.Clear(Color.FromArgb(255, m_r % 255, m_g % 255, m_b % 255));

                    // For testing purposes, sometimes it's useful to clear to a solid color
                    //g.Clear(Color.Red);

                    // Draw a pie chart segment on the background, simply because we can
                    g.FillPie(Brushes.BlueViolet, r1, m_iFrameNumber, (m_iFrameNumber + 123) % 360);
                }
                finally
                {
                    g.Dispose();
                }

                // Convert the RGB bitmap to the appropriate output format
                iRead = ConvertImage.ToFormat((int)m_SubType, m_Width, m_Height, m_Stride, m_pData, ip);
                Debug.Assert(iRead <= iSize);

                // Reset for the next call
                m_r += 1;
                m_g += 3;
                m_b += 7;
            }
            else
            {
                hr    = S_False; // End of stream
                iRead = 0;
            }

            return(hr);
        }