I want to capture only some part of desktop screen. for example I've opened 4,5 different window explorer, browsers, some MS office files and other stuff. and I want to take screenshot which only include some of them(windows). Not All windows.
string appPath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) + @"\screenshots\";
string imgName = name + DateTime.Now.Ticks + @".JPEG";
Bitmap memoryImage = null;
Graphics memoryGraphics = null;
int width = Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenWidth);
int height = Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenHeight);
System.Drawing.Size s = new System.Drawing.Size(width, height);
string str = "";
try
{
str = appPath + imgName;
}
catch (Exception er)
{
MessageBox.Show(er.Message.ToString());
}
using (memoryImage = new Bitmap(width, height))
{
using (memoryGraphics = Graphics.FromImage(memoryImage))
{
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
memoryImage.Save(str);
}
}
memoryImage.Dispose();
memoryGraphics.Dispose();
I'm using above code, which simple give me screenshot of my desktop.