Example #1
0
        public static void getDesktop(Packets.ServerPackets.GetDesktop packet, ClientMosaic client)
        {
            byte[]    desktop;
            Rectangle bounds = Screen.AllScreens[packet.monitor].Bounds;
            Bitmap    bitmap = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
            Graphics  graph  = Graphics.FromImage(bitmap);

            graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
            using (var stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Png);
                desktop = stream.ToArray();
            }
            new GetDesktopResponse(desktop, packet.monitor).Execute(client);
        }
Example #2
0
        public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Client client)
        {
            if (StreamCodec == null || StreamCodec.ImageQuality != command.Quality ||
                StreamCodec.Monitor != command.Monitor)
            {
                StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor);
            }

            BitmapData bmpdata = null;

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

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

                StreamCodec = null;
            }
            finally
            {
                if (LastDesktopScreenshot != null)
                {
                    if (bmpdata != null)
                    {
                        LastDesktopScreenshot.UnlockBits(bmpdata);
                    }
                    LastDesktopScreenshot.Dispose();
                }
            }
        }
Example #3
0
        public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Client client)
        {
            var resolution = FormatHelper.FormatScreenResolution(ScreenHelper.GetBounds(command.Monitor));

            if (StreamCodec == null)
            {
                StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
            }

            if (StreamCodec.ImageQuality != command.Quality || StreamCodec.Monitor != command.Monitor ||
                StreamCodec.Resolution != resolution)
            {
                if (StreamCodec != null)
                {
                    StreamCodec.Dispose();
                }

                StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
            }

            BitmapData desktopData = null;
            Bitmap     desktop     = null;

            try
            {
                desktop     = ScreenHelper.CaptureScreen(command.Monitor);
                desktopData = desktop.LockBits(new Rectangle(0, 0, desktop.Width, desktop.Height),
                                               ImageLockMode.ReadWrite, desktop.PixelFormat);

                using (MemoryStream stream = new MemoryStream())
                {
                    if (StreamCodec == null)
                    {
                        throw new Exception("StreamCodec can not be null.");
                    }
                    StreamCodec.CodeImage(desktopData.Scan0,
                                          new Rectangle(0, 0, desktop.Width, desktop.Height),
                                          new Size(desktop.Width, desktop.Height),
                                          desktop.PixelFormat, stream);
                    new Packets.ClientPackets.GetDesktopResponse(stream.ToArray(), StreamCodec.ImageQuality,
                                                                 StreamCodec.Monitor, StreamCodec.Resolution).Execute(client);
                }
            }
            catch (Exception)
            {
                if (StreamCodec != null)
                {
                    new Packets.ClientPackets.GetDesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor,
                                                                 StreamCodec.Resolution).Execute(client);
                }

                StreamCodec = null;
            }
            finally
            {
                if (desktop != null)
                {
                    if (desktopData != null)
                    {
                        try
                        {
                            desktop.UnlockBits(desktopData);
                        }
                        catch
                        {
                        }
                    }
                    desktop.Dispose();
                }
            }
        }