- // declaration de l'api P/Invoke
- // Ce code doit etre mis dans une class héritant de la classe Form
- [DllImport("coredll.dll")]
- public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
-
- const int SRCCOPY = 0x00CC0020;
-
- private void Snapshot(string fileName)
- {
- Graphics gx = this.CreateGraphics();
- Rectangle rect = Screen.PrimaryScreen.Bounds;
- Bitmap bmp = new Bitmap(rect.Width, rect.Height);
- // Creation d'un objet graphics compatible
- Graphics gxComp = Graphics.FromImage(bmp);
- // Prendre la photo
- BitBlt(gxComp.GetHdc(), 0, 0, rect.Width, rect.Height, gx.GetHdc(), rect.Left, rect.Top, SRCCOPY);
- // Enregistrement dans un fichier
- bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
- // Cleanup
- bmp.Dispose();
- gxComp.Dispose();
- }
// declaration de l'api P/Invoke
// Ce code doit etre mis dans une class héritant de la classe Form
[DllImport("coredll.dll")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
const int SRCCOPY = 0x00CC0020;
private void Snapshot(string fileName)
{
Graphics gx = this.CreateGraphics();
Rectangle rect = Screen.PrimaryScreen.Bounds;
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
// Creation d'un objet graphics compatible
Graphics gxComp = Graphics.FromImage(bmp);
// Prendre la photo
BitBlt(gxComp.GetHdc(), 0, 0, rect.Width, rect.Height, gx.GetHdc(), rect.Left, rect.Top, SRCCOPY);
// Enregistrement dans un fichier
bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
// Cleanup
bmp.Dispose();
gxComp.Dispose();
}