Autor Beitrag
sharpx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 51



BeitragVerfasst: Fr 09.01.09 11:06 
Hallo,

Kleine Server/Client anwendung:

client:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
string get_screen_info ()
    {
      StreamReader sr = new StreamReader("C://file_.jpg");
      string tmp = sr.ReadToEnd();
      sr.Close();
      
      return tmp;
    }

void capture_screen()
    {
      bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
      gfxScreenshot = Graphics.FromImage(bmpScreenshot);
      gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 00, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
      bmpScreenshot.Save("C://file_.jpg", ImageFormat.Jpeg);
    }


// ... OTHER FUNCTION ... //
stuff stuff stuff...

case "capture":
            capture_screen();
            sw.WriteLine(get_screen_info());
            sw.Flush();
            break;



server:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
void command (string cmd)
    {
      try
      {
        TcpClient tc = new TcpClient(current_ip, 9999);
        StreamWriter sw = new StreamWriter(tc.GetStream());
        StreamReader sr = new StreamReader(tc.GetStream());
        
        sw.WriteLine(cmd);
        sw.Flush();
        
        if (cmd == "capture")
        {
          string utmp = sr.ReadToEnd();
          
          StreamWriter slw = new StreamWriter("C:\\tmp.jpg");
          slw.Write(utmp);
          slw.Close();
        }
        
        sw.Close();
        sr.Close();
        tc.Close();
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString());
      }
    }



Das bild kommt an und wird auch unter c:/tmp.jpg gespeichert.
Jedoch kann ich es mir nicht ansehen, weil es anscheinend kein gültiges Bild ist?

Das Bild, welches der Client ausliest, kann ich jedoch betrachten und funktioniert auch.


Danke für eure Hifle!


Moderiert von user profile iconKha: Topic aus WinForms verschoben am Fr 09.01.2009 um 10:43
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Fr 09.01.09 13:38 
Ich weiß nicht, ob Dein Vorgehen sinnvoll ist (ich habe noch nie Dateien übers Netzwerk gesendet). Ich wundere mich aber über diese Zeile:
ausblenden C#-Quelltext
1:
string tmp = sr.ReadToEnd();   //  gleiche Situation noch an einer anderen Stelle					

Der Stream, der ein Bild enthält, soll als Unicode-String verarbeitet werden?

Ich vermute, dass eine Lösung mit einem byte-Array viel besser passen würde, und schlage einen Weg mit File.ReadAllBytes vor.

Jürgen