Example #1
0
 /**更新关键帧*/
 private void updateKeyFrame(Bitmap btm, ShortPoint cursorPoint)
 {
     if (btm != null)
     {
         globalCompareBitmap = (Bitmap)btm.Clone();
         BitmapWithCursor bitmapWithCursor = new BitmapWithCursor();
         bitmapWithCursor.setPacketType(RecPacket.PacketType.BITMAP);
         bitmapWithCursor.setCursorPoint(cursorPoint);
         bitmapWithCursor.setScreenBitmap(btm);
         /**添加到队列*/
         displayQueue.Enqueue(bitmapWithCursor);
     }
 }
Example #2
0
        /**显示线程*/
        private void dispalyBitmapFun()
        {
            while (isConnect)
            {
                try
                {
                    BitmapWithCursor bitmapWithCursor = displayQueue.Dequeue();
                    if (bitmapWithCursor != null)
                    {
                        RecPacket.PacketType packetType = bitmapWithCursor.getPacketType();
                        switch (packetType)
                        {
                        case RecPacket.PacketType.BITMAP:
                            Bitmap display = bitmapWithCursor.getScreenBitmap();
                            // Point cursorPoint = new Point(bitmapWithCursor.getCursorPoint().getXPoint(), bitmapWithCursor.getCursorPoint().getYPoint());
                            //using (Graphics g = Graphics.FromImage(bitmapWithCursor.getScreenBitmap()))
                            //{
                            //    Cursor myCursor = Cursor.Current;

                            //    myCursor.Draw(g, new Rectangle(cursorPoint, new Size(10, 10)));
                            //    g.Dispose();
                            //}
                            bitmapWidth  = display.Width;
                            bitmapHeight = display.Height;
                            scaleX       = (float)pictureBoxRec.Width / bitmapWidth;
                            scaleY       = (float)pictureBoxRec.Height / bitmapHeight;
                            pictureBoxRec.BackgroundImage = display;
                            labeldispalyQueue.Text        = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n";
                            break;

                        case RecPacket.PacketType.TEXT:
                            textBoxInfo.Text       = bitmapWithCursor.getStringValue();
                            labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n";
                            break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #3
0
        private void bitmapCmpToBlockingQueue()
        {
            while (isSendPic)
            {
                while (!picFlag)
                {
                    try
                    {
                        manulResetEvent.WaitOne();
                    }
                    catch (ThreadInterruptedException ex)
                    {
                        manulResetEvent.Reset();
                        Console.WriteLine(ex.Message);
                        ErrorInfo.getErrorWriter().writeErrorMassageToFile(ex.Message);
                        return;
                    }
                }
                while (picFlag)
                {
                    BitmapWithCursor bitmapWithCursor = screenCopyQueue.Dequeue();

                    if (bitmapWithCursor != null)
                    {
                        // Console.WriteLine("btmCmpThread***********");
                        try
                        {
                            //发送关键帧,校准
                            //keyFrameAdjusttimes++;
                            //if (keyFrameAdjusttimes > 300)
                            //{
                            //    keyFrameAdjusttimes = 0;
                            //    sendKeyFrame();
                            //}
                            Bitmap btm1 = bitmapWithCursor.getScreenBitmap();

                            if (isFirstFrame)
                            {
                                globalBtmWidth  = btm1.Width;
                                globalBtmHeight = btm1.Height;
                                upDateKeyFrame(btm1, bitmapWithCursor.getCursorPoint());
                                isFirstFrame = false;
                            }
                            else
                            {
                                int lastBtmWidth  = btm1.Width;
                                int lastBtmHeight = btm1.Height;
                                if (lastBtmWidth != globalBtmWidth || lastBtmHeight != globalBtmHeight)
                                {
                                    globalBtmWidth  = lastBtmWidth;
                                    globalBtmHeight = lastBtmHeight;
                                    upDateKeyFrame(btm1, bitmapWithCursor.getCursorPoint());
                                    continue;
                                }
                                Bitmap btm2 = globalComparerBitmap;

                                List <ShortRec> difPoints = null;
                                if (isWin8Above)
                                {
                                    // Stopwatch sw = new Stopwatch();
                                    //sw.Start();
                                    difPoints = BitmapCmp32Bit.Compare(bitmapWithCursor.dirtyRecs, btm2, btm1, bitCmpSize);
                                    //sw.Stop();
                                    //Console.WriteLine(sw.ElapsedMilliseconds+"ms");
                                }
                                else
                                {
                                    difPoints = BitmapCmp24Bit.Compare(btm1, btm2, bitCmpSize);
                                }
                                Bitmap sendPic = null;
                                if (difPoints.Count > 0)
                                {
                                    DifferentBitmapWithCursor differentBitmapWithCursor = new ScreenBitmap.DifferentBitmapWithCursor();
                                    double VPTNOW = (double)(CopyScreen.getReslution().Width *CopyScreen.getReslution().Height) / (bitCmpSize.Width * bitCmpSize.Height);
                                    if ((double)difPoints.Count >= VPT07 * VPTNOW)//超过70%的改变,直接发送K帧
                                    {
                                        sendPic = btm1;
                                        differentBitmapWithCursor.setBitmapType(SendPacket.BitmapType.COMPLETE);
                                    }
                                    else
                                    {
                                        //Stopwatch sw = new Stopwatch();
                                        //sw.Start();
                                        sendPic = GetDifBlocks.getBlocksIn1BitmapClone(difPoints, btm1, bitCmpSize);
                                        //sw.Stop();
                                        //Console.WriteLine(sw.ElapsedMilliseconds+"ms");
                                        differentBitmapWithCursor.setBitmapType(SendPacket.BitmapType.BLOCK);
                                        differentBitmapWithCursor.setDifPointsList(difPoints);
                                    }
                                    /**更新全局比较帧*/
                                    globalComparerBitmap.Dispose();
                                    globalComparerBitmap = (Bitmap)btm1.Clone();
                                    differentBitmapWithCursor.setCursorPoint(bitmapWithCursor.getCursorPoint());
                                    differentBitmapWithCursor.setDifBitmap(sendPic);


                                    screenCopyDifQueue.Enqueue(differentBitmapWithCursor);
                                    textBoxDBQ.Text = "" + screenCopyDifQueue.getQueueSize();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            ErrorInfo.getErrorWriter().writeErrorMassageToFile(ex.Message);
                            return;
                        }
                    }
                }
            }
        }
Example #4
0
        /**
         * 控制扫描块的大小,块越大,扫描速度越快,但是发送的数据量就越大;
         * 块越小,扫描速度就越慢,但是发送的数据量就小;
         * 局域网一般100*100
         * 广域网一般40*40 或 20*20
         * 是否需要协商块的大小????进一步实验决定。默认的事30*30,
         * 现在已经完全由server决定,client不需要blocksize
         **/
        //private static Size bitCmpSize = new Size(30, 30);
        /**图形恢复函数*/
        private void recoverBitmapFun()
        {
            while (isConnect)
            {
                try
                {
                    DifferentBitmapWithCursor difbitWithCur = deCompressDifQueue.Dequeue();
                    if (difbitWithCur != null)
                    {
                        RecPacket.PacketType packetType       = difbitWithCur.getPacketType();
                        BitmapWithCursor     bitmapWithCursor = new BitmapWithCursor();
                        bitmapWithCursor.setPacketType(packetType);
                        switch (packetType)
                        {
                        case RecPacket.PacketType.BITMAP:
                            RecPacket.BitmapType type        = difbitWithCur.getBitmapType();
                            ShortPoint           cursorpoint = difbitWithCur.getCursorPoint();
                            Bitmap          btm       = difbitWithCur.getDifBitmap();
                            List <ShortRec> difPoints = difbitWithCur.getDifPointsList();
                            switch (type)
                            {
                            case RecPacket.BitmapType.BLOCK:
                                //Stopwatch sw = new Stopwatch();
                                //sw.Start();
                                Bitmap recBitmap = RecoverBitmap.recoverScreenBitmap(difPoints, globalCompareBitmap, btm /*, bitCmpSize*/);
                                //sw.Stop();
                                //Console.WriteLine("client:"+sw.ElapsedMilliseconds+"ms");
                                bitmapWithCursor.setCursorPoint(cursorpoint);
                                bitmapWithCursor.setScreenBitmap(recBitmap);
                                globalCompareBitmap = (Bitmap)recBitmap.Clone();
                                /**放到显示队列*/
                                displayQueue.Enqueue(bitmapWithCursor);
                                break;

                            case RecPacket.BitmapType.COMPLETE:
                                updateKeyFrame(btm, cursorpoint);
                                break;

                            default:
                                break;
                            }
                            labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n";
                            break;

                        case RecPacket.PacketType.TEXT:
                            bitmapWithCursor.setStringValue(difbitWithCur.getStringValue());
                            displayQueue.Enqueue(bitmapWithCursor);
                            labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n";
                            break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #5
0
        private void copyScreenToBlockingQueue()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            int  fps       = 0;//统计FPS
            bool nullFrame = true;

            while (isSendPic)
            {
                while (!picFlag)
                {
                    try
                    {
                        manulResetEvent.WaitOne();
                    }
                    catch (ThreadInterruptedException ex)
                    {
                        manulResetEvent.Reset();
                        Console.WriteLine(ex.Message);
                        ErrorInfo.getErrorWriter().writeErrorMassageToFile(ex.Message);
                        return;
                    }
                }
                while (picFlag)
                {
                    try
                    {
                        Thread.Sleep(dynamicTime);
                        // Console.WriteLine("screenCopyThread***********");
                        if (isWin8Above)//above win8 version
                        {
                            /**采用DXGI形式获取桌面,只能使用在win8以上系统,效率比较高,用来代替Mirror Driver*/
                            DesktopFrame frame = CopyScreen.getScreenPicDXGI();
                            if (frame != null)
                            {
                                if (nullFrame)
                                {
                                    //第一针总是黑屏,所以直接舍弃
                                    nullFrame = false;
                                    continue;
                                }
                                fps++;
                                BitmapWithCursor bitmapWithCursor = new BitmapWithCursor();
                                bitmapWithCursor.setCursorPoint(new ShortPoint(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y));
                                bitmapWithCursor.setScreenBitmap(frame.DesktopImage);
                                bitmapWithCursor.dirtyRecs = frame.UpdatedRegions;
                                screenCopyQueue.Enqueue(bitmapWithCursor);
                                textBoxCSQ.Text = "" + screenCopyQueue.getQueueSize();
                            }
                        }
                        else//below win8
                        {
                            int cursorX, cursorY;
                            /* 采用的GDI形式获取桌面图形,效率比较低*/
                            Bitmap btm = CopyScreen.getScreenPic(out cursorX, out cursorY);
                            if (btm != null)
                            {
                                fps++;
                                BitmapWithCursor bitmapWithCursor = new BitmapWithCursor();
                                bitmapWithCursor.setCursorPoint(new ShortPoint(cursorX, cursorY));
                                bitmapWithCursor.setScreenBitmap(btm);
                                screenCopyQueue.Enqueue(bitmapWithCursor);
                                textBoxCSQ.Text = "" + screenCopyQueue.getQueueSize();
                            }
                        }

                        /**fps count*/
                        if (sw.ElapsedMilliseconds > 1000)
                        {
                            sw.Restart();
                            textBoxFPS.Text = "" + fps;
                            fps             = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        ErrorInfo.getErrorWriter().writeErrorMassageToFile(ex.Message);
                        return;
                    }
                }
            }
        }