Ejemplo n.º 1
0
        /// <summary>
        /// 组件改变大小时使用
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResizeSelf(object sender, EventArgs e)
        {
            if (OSPictureBox != null)
            {
                if (m_framebufferdata != null)
                {
                    if ((m_framebufferdata.w * OSPictureBox.Height) >= (OSPictureBox.Width * m_framebufferdata.h))
                    {
                        m_truedrawrect.Width  = OSPictureBox.Width;
                        m_truedrawrect.Height = (OSPictureBox.Width * m_framebufferdata.h) / m_framebufferdata.w;
                        m_truedrawrect.X      = 0;
                        m_truedrawrect.Y      = (OSPictureBox.Height - m_truedrawrect.Height) / 2;
                    }
                    else
                    {
                        m_truedrawrect.Height = OSPictureBox.Height;
                        m_truedrawrect.Width  = (OSPictureBox.Height * m_framebufferdata.w) / m_framebufferdata.h;
                        m_truedrawrect.X      = (OSPictureBox.Width - m_truedrawrect.Width) / 2;
                        m_truedrawrect.Y      = 0;
                    }
                }

                m_maing = OSPictureBox.CreateGraphics();
                m_maing.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Low;
                m_maing.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                m_maing.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 设置绘制对象
 /// </summary>
 private void SetGraphics()
 {
     m_maing = OSPictureBox.CreateGraphics();
     m_maing.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Low;
     m_maing.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
     m_maing.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
 }
Ejemplo n.º 3
0
        private void Update(FrameBufferData fb)
        {
            IntPtr date   = fb.data;
            int    length = fb.length;
            int    w      = fb.w;
            int    h      = fb.h;
            int    left   = fb.left;
            int    top    = fb.top;
            int    right  = fb.right;
            int    bottom = fb.bottom;

            //lock (locker)
            try
            {
                if (m_mainimg == null)
                {
                    m_mainimg = new Bitmap(w, h, PixelFormat.Format32bppRgb);
                }

                if (m_truedrawrect.Width == 0)
                {
                    if ((w * OSPictureBox.Height) >= (OSPictureBox.Width * h))
                    {
                        m_truedrawrect.Width  = OSPictureBox.Width;
                        m_truedrawrect.Height = (OSPictureBox.Width * h) / w;
                        m_truedrawrect.X      = 0;
                        m_truedrawrect.Y      = (OSPictureBox.Height - m_truedrawrect.Height) / 2;
                    }
                    else
                    {
                        m_truedrawrect.Height = OSPictureBox.Height;
                        m_truedrawrect.Width  = (OSPictureBox.Height * w) / h;
                        m_truedrawrect.X      = (OSPictureBox.Width - m_truedrawrect.Width) / 2;
                        m_truedrawrect.Y      = 0;
                    }

                    m_maing = OSPictureBox.CreateGraphics();
                    m_maing.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Low;
                    m_maing.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                    m_maing.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                }

                byte[] m_imgData = new byte[length];

                try
                {
                    Marshal.Copy(date, m_imgData, 0, length);
                    BitmapData bitdata = m_mainimg.LockBits(
                        new Rectangle(0, 0, m_mainimg.Width, m_mainimg.Height),
                        ImageLockMode.WriteOnly,
                        PixelFormat.Format32bppRgb);
                    Marshal.Copy(m_imgData, 0, bitdata.Scan0, m_imgData.Length);
                    m_mainimg.UnlockBits(bitdata);
                    m_maing.DrawImage(m_mainimg,
                                      m_truedrawrect,
                                      new Rectangle(0, 0, w, h),
                                      GraphicsUnit.Pixel);
                }
                catch (AccessViolationException)
                {
                    Trace.WriteLine("内存托管错误");
                }
            }
            catch (Exception)
            {
            }
        }