Beispiel #1
0
        private byte[] Capture()
        {
            try
            {
                Bitmap bitmap = new Bitmap(this.Canvas.Size.Width, this.Canvas.Size.Height);
                using (GraphicsBase g = GraphicsGDIPuls.FromImage(bitmap))
                {
                    this.Canvas.Draw(g);
                }
                BitmapData imageData = bitmap.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                byte[]     bs        = new byte[_width * _height * 3];
                Marshal.Copy(imageData.Scan0, bs, 0, bs.Length);
                bitmap.UnlockBits(imageData);
                bitmap.Dispose();
                var @out = _ffscale.Convert(bs);
                return(@out);
            }
            catch (Exception e)
            {
                //if (AppConfig._D)
                //    throw;

                return(null);
            }
        }
Beispiel #2
0
        private bool _Draw(byte[] buffer)
        {
            var rgb = _scale.Convert(buffer);

            if (_image == null)
            {
                _image = new Bitmap(_width, _height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            }

            BitmapData imageData = _image.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Marshal.Copy(rgb, 0, imageData.Scan0, rgb.Length);

            _image.UnlockBits(imageData);
            try {
                if (_control.IsHandleCreated && !_control.IsDisposed)
                {
                    var g = _control.CreateGraphics();
                    g.DrawImage(_image, new Rectangle(0, 0, _control.Width, _control.Height));
                    g.Dispose();
                }
            } catch (Exception e) {
                if (_control.IsHandleCreated && !_control.IsDisposed)
                {
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }
Beispiel #3
0
        private void YUVFrame(object sender, AForge.Video.DirectShow.RGBRawFrameEventArgs e)
        {
            byte[] buffer = FunctionEx.IntPtrToBytes(e.Buffer, 0, e.Len);
            buffer = _ffscale.Convert(buffer);

            if (_callBack != null)
            {
                _callBack(buffer);
            }
        }
Beispiel #4
0
        private byte[] Capture()
        {
            //if (AppConfig._D)
            //    return Capture_D();

            try
            {
                int _CX = 0, _CY = 0;
                var dt = DateTime.Now;

                Bitmap bmp = new Bitmap(GetSystemMetrics(0), GetSystemMetrics(1));
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
                    //var bmp_tmp = CaptureCursor(ref _CX, ref _CY);
                    //g.DrawImage(bmp_tmp, _CX, _CY);
                    g.Dispose();
                }
                var bmp1 = KiResizeImage(bmp, _width, _height);

                bmp.Dispose();

                bmp = bmp1;

                BitmapData imageData = bmp.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                byte[]     bs        = new byte[_width * _height * 3];
                Marshal.Copy(imageData.Scan0, bs, 0, bs.Length);
                bmp.UnlockBits(imageData);
                var @out = _ffscale.Convert(bs);
                return(@out);
            }
            catch (Exception e)
            {
                //if (AppConfig._D)
                //    throw;

                return(null);
            }
        }
Beispiel #5
0
        //回调函数
        private void SampleGrabber_Callback(double SampleTime, IntPtr pBuf, int len)
        {
            if (_isDisoseing || _isDisosed)
            {
                return;
            }

            if (!_isworking)
            {
                return;
            }

            var buf = FunctionEx.IntPtrToBytes(pBuf, 0, len);

            buf = _ffscale.Convert(buf);

            if (_callBack != null)
            {
                _callBack(buf);
            }
        }
Beispiel #6
0
        protected void CameraCapturer_CallBack(byte[] yuv)
        {
            if (!_isworking)
            {
                return;
            }
            try
            {
                Draw(yuv);

                if ((Environment.TickCount - _lastTick) < 1000 / _fps)
                {
                    return;
                }

                _lastTick = Environment.TickCount;

                var yv12 = _ffscale.Convert(yuv);

                if (_needForceIDRFrame)
                {
                    _needForceIDRFrame = false;
                    _x264.ForceIDRFrame();
                }

                var enc = _x264.Encode(yv12);



                var mf = new MediaFrame()
                {
                    Width             = _cfgVideo.Width,
                    Height            = _cfgVideo.Height,
                    Ex                = 1,
                    IsAudio           = 0,
                    Encoder           = MediaFrame.H264Encoder,
                    IsKeyFrame        = (byte)(_x264.IsKeyFrame() ? 1 : 0),
                    MediaFrameVersion = 0,
                    PPSLen            = 0,
                    SPSLen            = 0,
                    Size              = enc.Length,
                    NTimetick         = Environment.TickCount,
                };
                mf.SetData(enc);
                if (mf.IsKeyFrame == 1)
                {
                    var sps_pps = Media.MediaSteamConverter.GetSPS_PPS(enc);
                    mf.SPSLen = sps_pps[0].Length;
                    mf.PPSLen = sps_pps[1].Length;
                }
                mf.MediaFrameVersion = mf.IsKeyFrame;



                if (_needClearVideoTransportBuffer)
                {
                    _needClearVideoTransportBuffer = false;
                    var frame = CreateClearVideoTransportBufferMediaFrame(mf);
                    if (_callBack != null)
                    {
                        _callBack(frame);
                    }
                }

                if (_isFirstKeyFrame)
                {
                    if (mf.IsKeyFrame == 1)
                    {
                        mf.Ex = 0;
                    }
                    _isFirstKeyFrame = false;
                    var frame = CreateResetCodecMediaFrame(mf);
                    if (_callBack != null)
                    {
                        _callBack(frame);
                    }
                }

                if (_callBack != null)
                {
                    _callBack(mf);
                }
            }
            catch (Exception e)
            {
                if (_isworking)
                {
                    throw;
                }
            }
        }