How to capture snap of any SDI windowForm including title bar
-
below is my routine which works fine but the routine is not generating the image of sdi form with proper height & width. here is my routine and i think there is flaw but i am not being able to capture & fix the flaw. so here is my code. please have a look and guide me what i need to change in this code to fix this flaw.
protected virtual void OnMinimize(EventArgs e)
{
Rectangle r = this.RectangleToScreen(this.ClientRectangle);
int titleHeight = r.Top - this.Top;\_lastSnapshot = new Bitmap(r.Width, r.Height); using (Image windowImage = new Bitmap(r.Width, r.Height + titleHeight)) using (Graphics windowGraphics = Graphics.FromImage(windowImage)) using (Graphics tipGraphics = Graphics.FromImage(\_lastSnapshot)) { windowGraphics.CopyFromScreen(new Point(r.Left, r.Top - titleHeight), new Point(0, 0), new Size(r.Width, r.Height + titleHeight)); windowGraphics.Flush(); tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height + titleHeight); \_lastSnapshot.Save(@".\\tmp.bmp", ImageFormat.Bmp); }
}
with the help of above routine i could generate form image and just click on the link to check. http://i.stack.imgur.com/wCvUl.png[^]
tbhattacharjee
-
below is my routine which works fine but the routine is not generating the image of sdi form with proper height & width. here is my routine and i think there is flaw but i am not being able to capture & fix the flaw. so here is my code. please have a look and guide me what i need to change in this code to fix this flaw.
protected virtual void OnMinimize(EventArgs e)
{
Rectangle r = this.RectangleToScreen(this.ClientRectangle);
int titleHeight = r.Top - this.Top;\_lastSnapshot = new Bitmap(r.Width, r.Height); using (Image windowImage = new Bitmap(r.Width, r.Height + titleHeight)) using (Graphics windowGraphics = Graphics.FromImage(windowImage)) using (Graphics tipGraphics = Graphics.FromImage(\_lastSnapshot)) { windowGraphics.CopyFromScreen(new Point(r.Left, r.Top - titleHeight), new Point(0, 0), new Size(r.Width, r.Height + titleHeight)); windowGraphics.Flush(); tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height + titleHeight); \_lastSnapshot.Save(@".\\tmp.bmp", ImageFormat.Bmp); }
}
with the help of above routine i could generate form image and just click on the link to check. http://i.stack.imgur.com/wCvUl.png[^]
tbhattacharjee
Unfortunately the
ClientRectangle
does not include the form borders so that is not useful for capturing the complete window. However the actual location and size is kept in the form's properties and can be used to capture the window as below. And in this case, the title bar size is not needed.Rectangle r = new Rectangle(this.Left, this.Top, this.Width, this.Height);
Bitmap _lastSnapshot = new Bitmap(r.Width, r.Height);
using (Image windowImage = new Bitmap(r.Width, r.Height))
using (Graphics windowGraphics = Graphics.FromImage(windowImage))
using (Graphics tipGraphics = Graphics.FromImage(_lastSnapshot))
{
windowGraphics.CopyFromScreen(new Point(r.Left, r.Top), new Point(0, 0), new Size(r.Width, r.Height));
windowGraphics.Flush();tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height); \_lastSnapshot.Save(@".\\tmp.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
Use the best guess
-
Unfortunately the
ClientRectangle
does not include the form borders so that is not useful for capturing the complete window. However the actual location and size is kept in the form's properties and can be used to capture the window as below. And in this case, the title bar size is not needed.Rectangle r = new Rectangle(this.Left, this.Top, this.Width, this.Height);
Bitmap _lastSnapshot = new Bitmap(r.Width, r.Height);
using (Image windowImage = new Bitmap(r.Width, r.Height))
using (Graphics windowGraphics = Graphics.FromImage(windowImage))
using (Graphics tipGraphics = Graphics.FromImage(_lastSnapshot))
{
windowGraphics.CopyFromScreen(new Point(r.Left, r.Top), new Point(0, 0), new Size(r.Width, r.Height));
windowGraphics.Flush();tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height); \_lastSnapshot.Save(@".\\tmp.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
Use the best guess
thanks for your answer. i got another trick that is bit small and works well
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"d:\Zapps.bmp", ImageFormat.Bmp);tbhattacharjee
-
thanks for your answer. i got another trick that is bit small and works well
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"d:\Zapps.bmp", ImageFormat.Bmp);tbhattacharjee