M
Mahesh
Hello All,
I'm fairly new to System.Windows.Forms namespace.
I want to capture a screenshot of a form and want to save
it. I got a rough idea as to how to do it thru this link:
http://www.c-
sharpcorner.com/Code/2002/April/ScreenCaptureUtility.asp
But the developer has used Win32 API. I wanted to write a
pure .NET code. I tried to modify this code like this.
public void saveImage(string strFileName)
{
Graphics formGraphics = this.CreateGraphics();
Graphics fileGraphics = null;
try
{
Image objImage
= new Bitmap((int)formGraphics.VisibleClipBounds.Width,
(int)formGraphics.VisibleClipBounds.Height,formGraphics);
fileGraphics = Graphics.FromImage(objImage);
fileGraphics.DrawImage
(objImage,0,0,formGraphics.VisibleClipBounds.Width,formGrap
hics.VisibleClipBounds.Height);
objImage.Save("MyForm.jpg",ImageFormat.Jpeg);
}
finally
{
graphics.Dispose();
if(fileGraphics != null)
fileGraphics.Dispose();
}
}
Though this code is not croaking, but the image is not
saved. There is just a blank (black)image in place which
is saved. I don't know what I'm missing.
Is there some raster operation to be performed?
Please do let me know where my mistake is.
Thanx in advance.
Mahesh.
I'm fairly new to System.Windows.Forms namespace.
I want to capture a screenshot of a form and want to save
it. I got a rough idea as to how to do it thru this link:
http://www.c-
sharpcorner.com/Code/2002/April/ScreenCaptureUtility.asp
But the developer has used Win32 API. I wanted to write a
pure .NET code. I tried to modify this code like this.
public void saveImage(string strFileName)
{
Graphics formGraphics = this.CreateGraphics();
Graphics fileGraphics = null;
try
{
Image objImage
= new Bitmap((int)formGraphics.VisibleClipBounds.Width,
(int)formGraphics.VisibleClipBounds.Height,formGraphics);
fileGraphics = Graphics.FromImage(objImage);
fileGraphics.DrawImage
(objImage,0,0,formGraphics.VisibleClipBounds.Width,formGrap
hics.VisibleClipBounds.Height);
objImage.Save("MyForm.jpg",ImageFormat.Jpeg);
}
finally
{
graphics.Dispose();
if(fileGraphics != null)
fileGraphics.Dispose();
}
}
Though this code is not croaking, but the image is not
saved. There is just a blank (black)image in place which
is saved. I don't know what I'm missing.
Is there some raster operation to be performed?
Please do let me know where my mistake is.
Thanx in advance.
Mahesh.