Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

C# Screenshot flip flop not working

I am trying to do something very specific here; Essentially, what this code does:

else if (cmd == "streams")
                {
                    Console.WriteLine("Hello, thank you for testing out the streams beta.
Before you start, there are some things you should know.
 First off, all screenshots are saved to your documents folder. They are named streams and streams_green.
To stop recording, close the software.");
                    Console.WriteLine("Please enter your monitors resolution (RECORD WITH YOUR GAME IN FULLSCREEN WINDOWED)");
                    Console.WriteLine("X:");
                    int xres = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Y:");
                    int yres = Convert.ToInt32(Console.ReadLine());
                    p.Send(maxfps);
                    Console.WriteLine("Thank you, recording now started.");
                    Bitmap memoryImage;
                    memoryImage = new Bitmap(xres, yres);
                    Size s = new Size(memoryImage.Width, memoryImage.Height);
                    Graphics memoryGraphics = Graphics.FromImage(memoryImage);
                    for (var i = 0; ; i++)
                    {
                        memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
                        string str = "";
                        string str2 = "";
                        str = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                        $@"streams{i}.png");
                        str2 = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                        $@"streams_green{i}.png");
                        System.Threading.Thread.Sleep(2);
                        //Send spacebar would go here
                        p.Send(green);
                        memoryImage.Save(str);
                        System.Threading.Thread.Sleep(1);
                        p.Send(regular);
                        memoryImage.Save(str2);
                        System.Threading.Thread.Sleep(1);

                    }

Is send a dvar to a game, take a screenshot, and another dvar, then take another screenshot ect. As you can see by "p.Send(green)" and (regular). However, I have an issue. I am trying to have this save all of the greenscreen screenshots as streams_green, and the regular ones under streams. It is currently properly saving all of the files, however, the _green images are identical to the regular ones, even though the moment the green screenshot was taken was a completely different displayed frame as the one before it. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Based on the code your method takes only one screenshoot at line memoryGraphics.CopyFromScreen(0, 0, 0, 0, s); and then save it in two separate files by memoryImage.Save. If instancegreen (in line p.Send(green)) and instance regular (in line p.Send(regular)) have information you want to save then you should change them to Bitmap and save.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...