public static void UdpThread() { MainUI.SetCulture(); while (true) { var listenStuff = !MainUI.isHost ? MainUI.screenPartner : new IPEndPoint(IPAddress.Any, 8042); byte[] data = MainUI.screenClient.Receive(ref listenStuff); if (MainUI.screenPartner == null) { MainUI.screenPartner = listenStuff; } if (data.Length > 4 && !MainUI.isHost) { datas.Add(data); } } }
private void imageUpdater_Tick(object sender, EventArgs e) { if (!initImg && ScreenshotHandler.winSize.Width > 0) { initImg = true; pictureBox1.Image = new Bitmap(this.Width, this.Height); } if (ScreenshotHandler.winSize.Width > 0) { screenPercentageX = (float)this.Width / (float)ScreenshotHandler.winSize.Width; screenPercentageY = (float)this.Height / (float)ScreenshotHandler.winSize.Height; // Get our screen percentage } byte[] data; while (ScreenshotHandler.datas.TryTake(out data)) { string strData = MainUI.ByteToStr(data); if (strData.StartsWith("IMG")) // If it's an image { strData = strData.Split(new string[] { "|$|" }, StringSplitOptions.None)[0]; // Only get our header if (ScreenshotHandler.winSize.Width == 0) { string[] sizeData = strData.Split('|')[2].Split(','); ScreenshotHandler.winSize = new Size(int.Parse(sizeData[0]), int.Parse(sizeData[1])); } /*if(totalImage == null) * { * string[] sizeData = strData.Split('|')[2].Split(','); * totalImage = new Bitmap(int.Parse(sizeData[0]), int.Parse(sizeData[1])); // Make a total image if it's missing * }*/ string[] pointData = strData.Replace("{X=", "").Replace("}", "").Replace("Y=", "").Split('|')[1].Split(','); byte[] imgData = ScreenshotHandler.Decompress(ScreenshotHandler.GetImageData(data)); // Get the image bytes Point loc = new Point(int.Parse(pointData[0]), int.Parse(pointData[1])); // Get the box location MemoryStream imgMem = new MemoryStream(imgData); Image boxImg = Image.FromStream(imgMem); // Get image from bytes Bitmap boxBit = new Bitmap(boxImg); if (!ScreenshotHandler.imageBlocks.ContainsKey(loc)) { ScreenshotHandler.imageBlocks.Add(loc, boxBit); } else { ScreenshotHandler.imageBlocks[loc] = boxBit; } updated.Add(loc); pictureBox1.Invalidate(new Rectangle((int)((float)loc.X * screenPercentageX - 1), (int)((float)loc.Y * screenPercentageY), (int)((float)boxBit.Width * screenPercentageX + 1), (int)((float)boxBit.Height * screenPercentageY))); // Refresh the picturebox //pictureBox1.Update(); /*MainUI.screenshareForm.Invoke(() => { * /*int dW = (loc.X + boxImg.Width + 1) - totalImage.Width; * int dH = (loc.Y + boxImg.Height + 1) - totalImage.Height; * * if (dW > 0) // Crop width if it's too big * { * Bitmap toCrop = new Bitmap(boxImg); * boxImg = toCrop.Clone(new Rectangle(0, 0, toCrop.Width - dW, toCrop.Height), toCrop.PixelFormat); * toCrop.Dispose(); * } * if (dH > 0) // Crop height if it's too big * { * Bitmap toCrop = new Bitmap(boxImg); * boxImg = toCrop.Clone(new Rectangle(0, 0, toCrop.Width, toCrop.Height - dH), toCrop.PixelFormat); * toCrop.Dispose(); * } // Old client-side cropping (useless) * * using (Graphics g = Graphics.FromImage(totalImage)) // Draw the image on the totalImage * { * g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; * g.DrawImage(boxImg, loc); * } * boxImg.Dispose(); * });*/ //imgMem.Dispose(); // Clear memory } } }