В настоящее время я создаю средство просмотра удаленного рабочего стола через TCP и хочу передать это изображение и показать его в другой форме. В форме 2 изображение отображается пустым, и форма перестает работать через некоторое время.
Форма 1:
Form2 fm2 = new Form2();
int v = 0;
while(true){
//sendmessage to client
while(true){
stream = client.GetStream();
BinaryFormatter as1 = new BinaryFormatter();
pictureBox1.Image = (Image)as1.Deserialize(stream);
fm2.dImage(image);
if (v == 0) { fm2.Show(); v++; }
}
}
Форма 2:
public Form2()
{
InitializeComponent();
}
public void dImage(Image image)
{
this.pictureBox1.Image = image;
//pictureBox1.Invoke(new Action(() => pictureBox1.Image = image));
}
Клиент:
while (timerStart == true)
{
BinaryFormatter asd3 = new BinaryFormatter();
asd3.Serialize(stream, comands.GrabDesktop());
}
public static Image GrabDesktop()
{
Rectangle bounds = Screen.PrimaryScreen.Bounds;
Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics graphic = Graphics.FromImage(screenshot);
graphic.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
return screenshot;
}