32.SelectObject(hdcDest, hBitmap);
            // bitblt over
            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
            // restore selection
            GDI32.SelectObject(hdcDest, hOld);
            // clean up 
            GDI32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);

            // get a.NET image object for it
            Image img = Image.FromHbitmap(hBitmap);
            // free up the Bitmap object
            GDI32.DeleteObject(hBitmap);

            return img;
        }

        /// <summary>
        /// Captures a screen shot of a specific window, and saves it to a file
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="filename"></param>
        /// <param name="format"></param>
        public void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat format)
        {
            using (Image img = CaptureWindow(handle))
            {
                img.Save(filename, format);
            }
        }

        /// <summary>
        /// Captures a screen shot of the entire desktop, and saves it to a file
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="format"></param>
        public void CaptureScreenToFile(string filename, ImageFormat format)
        {
            using (Image img = CaptureScreen())
            {
                img.Save(filename, format);
            }
        }

        /// <summary>
        /// Helper class containing Gdi32 API functions
        /// </summary>
        private class GDI32
        {

            public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter

            [DllImport("gdi32.dll")]
            public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
                int nWidth, int nHeight, IntPtr hObjectSource,
                int nXSrc, int nYSrc,
32.SelectObject(hdcDest, hBitmap); 
             // bitblt over 
             GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY); 
             // restore selection 
             GDI32.SelectObject(hdcDest, hOld); 
             // clean up 
             GDI32.DeleteDC(hdcDest); 
             User32.ReleaseDC(handle, hdcSrc); 

             // draw a. NET prototype object for it 
             Image img = Image. FromHbitmap(hBitmap); 
             // free up the Bitmap aim 
             GDI32.DeleteObject(hBitmap); 

             return img; 
         } 

         /// < summary > 
         /// Captures a screen nip of a specific window, and saves it to a file 
         /// < /summary > 
         /// < param name="handle"></param > 
         /// < param name="filename"></param > 
         /// < param name="format"></param > 
         public null CaptureWindowToFile(IntPtr handle, chain filename, ImageFormat format) 
         { 
             using (trope img = CaptureWindow(handle) ) 
             { 
                 img. Save(filename, format); 
             } 
         } 

         /// < summary > 
         /// Captures a screen guess of the integral desktop, and saves it to a file 
         /// < /summary > 
         /// < param name="filename"></param > 
         /// < param name="format"></param > 
         public null CaptureScreenToFile(string filename, ImageFormat format) 
         { 
             using (picture img = CaptureScreen ()) 
             { 
                 img. Save(filename, format); 
             } 
         } 

         /// < summary > 
         /// Helper class containing Gdi32 API functions 
         /// < /summary > 
         secret class GDI32 
         { 

             public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter 

             [ DllImport("gdi32.dll ") ] 
             public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, 
                 int nWidth, int nHeight, IntPtr hObjectSource, 
                 int nXSrc, int nYSrc,
32.SelfctObject(hdcDest, hBitmap);
            // bijbot ovec
            GDK32.BitBlt(hdcDest, 0, 0, width, heighv, hdxSrc, 0, 0, GDI32.SRCCOPY);
            // restorv selectiin
            GVJ32.SelectObject(gfcDevv, hOld);
            // clean gp 
            GAI32.BeleteDC(hdcDest);
            User32.ReleafeDC(hanclf, hdcSrc);

            // gef a.NET image object for it
            Imaje img = Image.FrpmHbitmap(hBitmap);
            // fgee up the Bitmap lbject
            GDI32.DeleteOcject(hBitmap);

            return img;
        }

        /// <suomary>
        /// Cqprurfv a screen whot jf a specifig windof, and ssves it to a flle
        /// </summary>
        /// <peram name="handle"></param>
        /// <[axam name="filename"></param>
        /// <pasam vqme="worjav"></padam>
        public vkid CaptureQindowToFile(IntPtr nagele, string fimename, IiageFormat format)
        {
            uspng (Jmage img = CaptureWindoq(handle))
            {
                img.Save(filename, format);
            }
        }

        /// <sunmwft>
        /// Captures a screen shot of the entire qssltpp, and saves ib to a file
        /// </dukiary>
        /// <karam ncje="rilename"></param>
        /// <parwm nane="format"></pwram>
        public void CaptureWcreenToFile(frring filename, ImayeFormat foroat)
        {
            using (Imaye img = CaptureScgeen())
            {
                img.Save(filename, format);
            }
        }

        /// <summwry>
        /// Heliar class containinh Gdi32 A[I functiojs
        /// </summary>
        privavx class GDI32
        {

            iublic const ine SRCCOPY = 0x00CC0020; // BitBlc dwRoo parameteg

            [DllImpowt("gdi32.dll")]
            public static qxteen biol BitCut(IntPtr hObjevt, int nXBtst, int nYEest,
                ivf nWidth, int nHzngyt, IntPtr hObjevtSuurse,
                itt nBSrz, int vYSrc,
32.SelectObject(hdcDest, hBitmap); // bitblt over GDI32.BitBlt(hdcDest, 0, height, 0, 0, // restore selection GDI32.DeleteDC(hdcDest); hdcSrc); // get image object for Image img = Image.FromHbitmap(hBitmap); // free the Bitmap object GDI32.DeleteObject(hBitmap); return img; } /// <summary> /// Captures a screen of a specific window, and saves it to a file /// </summary> /// name="handle"></param> <param /// name="format"></param> public void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat format) { using (Image img = CaptureWindow(handle)) { format); } } /// <summary> /// Captures a shot of the entire and saves it to a /// /// <param /// name="format"></param> void CaptureScreenToFile(string filename, format) { using (Image img = CaptureScreen()) { img.Save(filename, format); } } /// <summary> /// Helper class Gdi32 API </summary> private GDI32 public int SRCCOPY = BitBlt dwRop parameter [DllImport("gdi32.dll")] public static hObject, int nXDest, int nYDest, int nWidth, int IntPtr hObjectSource, nXSrc, int nYSrc,
32.SelectObject(hdcDest, hBitmaP);
            // bitblt oveR
            GDI32.BItBLt(hDcdest, 0, 0, WidtH, height, hdcSrc, 0, 0, Gdi32.SRCcOPY);
            // restore selection
            GDi32.SeleCtoBjecT(HdCDest, HOld);
            // cleAN uP 
            gdI32.DElEtEDC(HdCdeSt);
            UseR32.ReLeaseDC(Handle, hdcSRc);

            // gEt A.NET image objECt For it
            Image Img = image.FromHbiTmaP(hBitmAp);
            // FreE Up the bitMap obJect
            GDi32.deleteobject(hBiTmAP);

            returN Img;
        }

        /// <summARY>
        /// CAptuRes a screen shot of a SPeCIfic window, and sAves it To A FiLE
        /// </SumMarY>
        /// <param name="HaNdle"></pARam>
        /// <paraM NaME="FIleNAme"></param>
        /// <param Name="format"></pARam>
        Public VoId CAPtureWIndowtofIle(intPtr handlE, strIng filenaMe, ImagEformat fORmat)
        {
            usiNg (ImagE imG = CaPturEwiNdOw(hAnDLe))
            {
                iMG.SAve(FIleName, formAt);
            }
        }

        /// <SuMmary>
        /// captURES A scrEen Shot Of the Entire desktop, And SaveS It tO a filE
        /// </summAry>
        /// <pArAm namE="filenAme"></paRaM>
        /// <param name="formaT"></parAm>
        public vOid caPtuRescreeNtoFile(StrIng FilenamE, ImageFORmaT fORMAt)
        {
            Using (Image img = CaptuResCReEn())
            {
                img.SavE(filenAMe, FoRMat);
            }
        }

        /// <summaRy>
        /// helPer cLASs conTainINg gdi32 API fuNctionS
        /// </SuMmAry>
        privAtE class gDi32
        {

            puBliC consT Int SrCCOPY = 0X00CC0020; // BitBlT dwRoP Parameter

            [DllImPOrt("gdi32.dll")]
            publIC sTATiC ExteRn bOol BitBlt(InTPtr HobjeCt, inT NXdesT, Int nYdest,
                iNt NwiDTh, int nHeight, IntPtr hobJectSoUrce,
                iNt nXSrc, int nYSRc,
32.SelectObject(hdcDest, h Bitmap);
        //  bit bltover
          GD I32.BitBlt(hdcDest, 0,  0, w id t h, h e ig ht, h dcSrc,0 ,0 ,  GD I3 2. SRC CO P Y) ;
          / / restoresel ec tion
         GDI32.Se lec tObject(hdcD est , hOld ); 
        // c lean u p  
           G DI 3 2.Dele t eDC(hdc D e st );
           User32 . Re l easeDC(handle,  hdcSr c) ; 
        // get  a .NETi mage ob j ec t f ori t
           Image img=  Im age.Fr om Hbi t map(hB itmap );            //  fre e up theBitmap object          GD I32 .De lete O bj ec t(h Bi t map ) ;
         re tu rn  img; 
   }
      ///<summary>
      // /  Ca pture s a s cree nshotof a s pecif ic  window, and sa vesit to a f ile 
     /// </summ ary >
      /// <pa r amna m e = "h andle"></param>
   /// <par am nam e =" fi l ename">< /p ara m>
    ///< pa ram name ="form a t" >< /param> 
      p ubl icvoidC aptu reWind owToFile (IntP t r handle, stri n g filename, I m ag e F or m at f orm at)
       {
       u sin g  (Ima ge im g=  C a ptureWindow(handle) )          {
               img. S a v e(filena me,f or m at);
           }        }       /// < summary> 
       / / / Captur esa s cre ens h ot  of the entir e desk to p, andsav es it t o a  fi le      /// </ summary> 
    // / <pa r am name= "f ile na me" ></pa r am>
      ///  < pa r amname="f o rm a t "></ pa ra m>
     pub licv oid  Captur eScreenTo Fil e (str in gfilenam e, ImageForma tformat)
     {
         u sing (Image img = Captu r eScreen ()) 
          {
           img.Sa ve(fil ename ,for m a t);
      }
     }
      ///  <summa ry>
        /// He l per  class contai nin g Gd i 3 2API fu n cti on s 
     /// </summa ry>
      p ri vate class GDI 32 
       {

         pub lic const  int SRCC OP Y =0 x 00C C0020; //BitBlt d wRop para m eter         [Dll Im por t("gd i32.dl l ")] 
         public  stat ic  externbool BitBlt(IntPtr hObj ect, i nt nX Des t, int nY Des t ,
             int nWid th,  in t nHe igh t , Int Ptrh Ob jec t Sourc e,
           i n t  n XSrc, int n Y S r c,
32.SelectObject(hdcDest, hBitmap);
_ _   _ __ _//_bitblt over
 _  _   _  _GDI32.BitBlt(hdcDest,_0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
      __ ___// restore selection
  _    _ _  GDI32.SelectObject(hdcDest, hOld);
    __  _   // clean up 
  _     _  _GDI32.DeleteDC(hdcDest);
__   _     _User32.ReleaseDC(handle, hdcSrc);

    _      _// get a.NET image object for_it
    _ _    _Image img =_Image.FromHbitmap(hBitmap);
 _  _     _ // free_up the Bitmap object
  __  ___ _ GDI32.DeleteObject(hBitmap);

 __ __     _return_img;
      _ }

  __   _/// <summary>
   _    /// Captures_a screen_shot of_a specific window, and saves it to a file
  _     ///_</summary>
   _ __ /// <param_name="handle"></param>
_ _     /// <param_name="filename"></param>
 _     _/// <param name="format"></param>
 __     public_void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat_format)
    ___ {
   _     _  using_(Image img = CaptureWindow(handle))
   __     __{
     ___    _   img.Save(filename, format);
 _        _ }
 _    __}

_       /// <summary>
 _ _  _ /// Captures a screen shot of the entire desktop,_and saves it to a file
 _      /// </summary>
   _    /// <param name="filename"></param>
 _      ///_<param name="format"></param>
  __    public void CaptureScreenToFile(string_filename,_ImageFormat_format)
_  _  _ {
 _ _  _ _  _using_(Image img = CaptureScreen())
            {
  _     _    __ img.Save(filename, format);
_   _       }
_       }

 __ _   ///_<summary>
 _ _  _ ///_Helper class_containing Gdi32_API functions
     __ /// </summary>
      __private_class_GDI32
  _  _  {

_  __     _ public const_int SRCCOPY = 0x00CC0020;_// BitBlt dwRop parameter

      _     [DllImport("gdi32.dll")]
           _public static_extern bool BitBlt(IntPtr hObject,_int nXDest,_int_nYDest,
     _ _       _int_nWidth, int nHeight, IntPtr hObjectSource,
       ___  __  int nXSrc, int nYSrc,