My goal is to be able to make a bitmap of a window, and just that window. I will also need to be able to make bitmaps of certain pixel regions within that window. These regions are not windows forms or anything like that.
I figured making a screen from the window handle, then writing regions of the screen that I need to a bitmap would be a good solution for this problem.
This is what I did:
Process[] processlist = Process.GetProcesses();
String[] process = null;
process = new string[200];
int i = 0;
IntPtr handle = IntPtr.Zero;
foreach (Process theprocess in processlist)
{
process[i] = theprocess.MainWindowTitle;
if (process[i].Contains("Title of Process"))
{
handle = theprocess.MainWindowHandle;
MessageBox.Show("Handle Set");
break;
}
i++;
}
//Sets new screen from Handle
Screen thescreen = Screen.FromHandle(handle);
//Bitmap stored
Bitmap bmpScreenshot = new Bitmap(thescreen.Bounds.Width, thescreen.Bounds.Height);
//Graphics object to draw screen in bitmap
Graphics g = Graphics.FromImage(bmpScreenshot);
//Copy from screen to bitmap
g.CopyFromScreen(0, 0, 0, 0, thescreen.Bounds.Size);
However, this just gets a bitmap of the entire screen. How can I reduce this to the size of just one window?
Thanks.