Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create bitmap of winform window by using TakeSnapshot(Control ctl) and BitmapToImageSource(Bitmap bitmap)method.
This code is work for Active window but not work for non active window.
Non active window bitmap is with active window portion which spread on it.
How to create bitmap of Non active window?

What I have tried:

public void CreateImagesOfCurrentOpenWindows()
{
  foreach (Form frm in Application.OpenForms)
  {
    var bitmap1 = TakeSnapshot(frm);
    //var bitmapImage = BitmapToImageSource(bitmap1);

    bitmap1.Save("" + frm.Name + "", System.Drawing.Imaging.ImageFormat.Jpeg);
  }
}

public static Bitmap TakeSnapshot(Control ctl)
{
  Bitmap bmp = new Bitmap(ctl.ClientRectangle.Width, ctl.ClientRectangle.Height);
  System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
  g.CompositingMode = CompositingMode.SourceCopy;
  g.CopyFromScreen(ctl.PointToScreen(ctl.ClientRectangle.Location), new Point(0, 0), ctl.ClientRectangle.Size);
  return bmp;
}
Posted
Updated 21-Jun-20 22:00pm
v2

1 solution

The Graphics.CopyFromScreen Method (System.Drawing) | Microsoft Docs[^] copies what is displayed on the physical screen. It cannot 'see' parts of Windows that are overlayed by others, as they are not actually on the screen.
 
Share this answer
 
Comments
Sandeep SS 22-Jun-20 4:44am    
ok, Thanks for suggestion.
Sandeep SS 22-Jun-20 4:45am    
so how to capture or create bitmap of non active windows?
Richard MacCutchan 22-Jun-20 5:03am    
You cannot capture information that is not visible on the screen. You need the Window to be active in the same way that the Windows Snipping tool does it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900