Пример #1
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            lock (this)
            {
                if (isDisposed)
                {
                    return;
                }
                if (!receivedMetaData)
                {
                    return;
                }

                CaptureScreen();
                BitmapXama convedXBmap = null;
                if (resolutionScale == 1)
                {
                    convedXBmap = convertToBitmapXamaAndRotate(bitmap);
                    socket.SendImage(convedXBmap, screenRect.Width, screenRect.Height, screenIndex, compress, targetFPS);
                }
                else
                {
                    convedXBmap = convertToBitmapXamaAndRotate(scaledBitmap);
                    socket.SendImage(convedXBmap, screenRect.Width, screenRect.Height, screenIndex, compress, targetFPS);
                }
            }
        }
Пример #2
0
        private unsafe BitmapXama convertToBitmapXamaAndRotate(Bitmap bmap)
        {
            //bmap.RotateFlip(RotateFlipType.Rotate90FlipY);
            bmap.RotateFlip(RotateFlipType.Rotate90FlipNone); // for OpenH264 encoder&decoder

            Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);

            BitmapData bmpData    = null;
            Bitmap     bmap16     = null;
            long       dataLength = -1;

            bmpData    = bmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmap.PixelFormat);
            dataLength = bmap.Width * bmap.Height * 3; //RGB24


            IntPtr       ptr          = bmpData.Scan0;
            MemoryStream ms           = new MemoryStream();
            var          bitmapStream = new UnmanagedMemoryStream((byte *)bmpData.Scan0, dataLength);

            bitmapStream.CopyTo(ms);
            bmap.UnlockBits(bmpData);


            //byte[] buf = ms.GetBuffer();
            byte[] buf     = ms.ToArray();
            var    retBmap = new BitmapXama(buf);

            retBmap.Height = bmap.Height;
            retBmap.Width  = bmap.Width;

            return(retBmap);
        }
Пример #3
0
        private void Timer_Tick_bitmap_to_openH264_Encoder(object sender, EventArgs e)
        {
            lock (this)
            {
                if (isFixedParamUse)
                {
                    resolutionScale = fixedResolutionScale;
                }

                CaptureScreen();
                if (timestamp < GlobalConfiguration.initialSkipCaptureNums)
                {
                    timestamp++;
                    return;
                }

                BitmapXama convedXBmap = null;
                byte[]     tmp_buf     = new byte[scaledBitmap.Width * scaledBitmap.Height * 3];
                if (resolutionScale == 1)
                {
                    convedXBmap = convertToBitmapXamaAndRotate(bitmap);
                }
                else
                {
                    convedXBmap = convertToBitmapXamaAndRotate(scaledBitmap);
                }

                if (convedXBmap.getInternalBuffer().Length == 0)
                {
                    return;
                }
                Array.Copy(convedXBmap.getInternalBuffer(), 0, tmp_buf, 0, tmp_buf.Length);
                var bitmap_ms = Utils.getAddHeaderdBitmapStreamByPixcels(tmp_buf, convedXBmap.Width, convedXBmap.Height);

                Console.WriteLine("write data as bitmap file byte data to encoder " + bitmap_ms.Length.ToString() + "Bytes timestamp=" + timestamp.ToString());
                encoder.addBitmapFrame(bitmap_ms.ToArray(), timestamp - GlobalConfiguration.initialSkipCaptureNums);
                timestamp++;
            }
        }
Пример #4
0
        private void h264RawDataHandlerSendTCP(byte[] data)
        {
            BitmapXama bmpXama = new BitmapXama(data);
            int        width;
            int        height;

            if (isFixedParamUse)
            {
                width  = (int)(screenRect.Width * fixedResolutionScale);
                height = (int)(screenRect.Height * fixedResolutionScale);
            }
            else
            {
                width  = (int)(screenRect.Width * resolutionScale);
                height = (int)(screenRect.Height * resolutionScale);
            }
            // 90度ひねっているので 縦横は逆に設定する
            bmpXama.Width  = height;
            bmpXama.Height = width;

            socket.SendImage(bmpXama, screenRect.Width, screenRect.Height, screenIndex, compress, targetFPS);
        }