views:

58

answers:

0

Why do I receive a black screen when using the following code to take a screenshot every 20 milliseconds and transmit it to a peer over an encrypted connection? (I am aware that 20 milliseconds is a bit fast of a refresh rate, but it seems that is not the problem. The processor and network can keep up quite well with the refresh rate, the problem is the fact that the bitmap appears completely black. EDIT: I now know it's some kinda strange network problem, but now the image shows up blurry, as though it's a bad analog signal. I have attached a screenshot of the program to this post. http://imgur.com/y9rWb.png

 P2PStream thestream = (P2PStream)sender;
        Bitmap mymap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
        Graphics screenshotGFX = Graphics.FromImage(mymap);
        screenshotGFX.CopyFromScreen(new Point(),new Point(),new Size(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height));
        Stream encryptedStream = networkLogic.getCryptoStream(thestream, true);
        while (true)
        {
            try
            {
                screenshotGFX.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                mymap.Save(encryptedStream,System.Drawing.Imaging.ImageFormat.Png);

            }
            catch (Exception)
            {
                MessageBox.Show("A client has disconnected");
                break;
            }
            System.Threading.Thread.Sleep(20);
        }