xXBeefyDjXx
Long time Sinner
Administrator
Hidden Devils
So Let me put this into context first, I am designing a bot for Piano Tiles 2 using C#, and figured that it'd be easiest to make it click the tiles using colour detection in a screenshot.
I have managed to make the bot work and press the blue start tile. (Hooray!)
But. It is capturing the whole screen, when in practice it only needs to capture a small line across the app to detect the scrolling tiles.
I would leave it capturing the whole screen but this is inefficient, and also because it scrolls from the top, down, this makes the bot hit the wrong tile, as it needs to scan from the bottom up, and hit the first tile nearest the bottom.
I also know once I have the optimised code for capturing the screen I would need to make it loop the code, but that is simple in practice and will be implemented later on.
My main question is how on earth do I make it capture a customisable section instead of the whole screen?
Here is the current code:
I have managed to make the bot work and press the blue start tile. (Hooray!)
But. It is capturing the whole screen, when in practice it only needs to capture a small line across the app to detect the scrolling tiles.
I would leave it capturing the whole screen but this is inefficient, and also because it scrolls from the top, down, this makes the bot hit the wrong tile, as it needs to scan from the bottom up, and hit the first tile nearest the bottom.
I also know once I have the optimised code for capturing the screen I would need to make it loop the code, but that is simple in practice and will be implemented later on.
My main question is how on earth do I make it capture a customisable section instead of the whole screen?
Here is the current code:
//Captures the screen, Crucial to bot running. DO NOT BREAK.
//Warning: This code is unoptimised and produces shots of the whole screen.
private Bitmap Screenshot()
{
Bitmap PTView = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(PTView);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
return PTView;
}
//Warning: This code is unoptimised and produces shots of the whole screen.
private Bitmap Screenshot()
{
Bitmap PTView = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(PTView);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
return PTView;
}