开发者

Screenshots taken contain only black pixels

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);
        }


This happened to be a networking error with the router (faulty XSF support), and is now fixed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜