Exemplo n.º 1
0
            public void Blit(User32DeviceContext hdcSrc, GDI32DeviceContext hdcDest)
            {
                // select the bitmap object
                IntPtr hOld = new IntPtr();

                try
                {
                    hOld = GDI32.SelectObject(hdcDest.DC, hBitmap);
                    // bitblt over
                    GDI32.BitBlt(
                        hdcDest.DC,
                        0, 0, size.Width, size.Height,
                        hdcSrc.DC,
                        0, 0, GDI32.SRCCOPY
                        );
                }
                finally
                {
                    // restore selection
                    if (hOld.ToInt32() != 0)
                    {
                        GDI32.SelectObject(hdcDest.DC, hOld);
                    }
                }
            }
Exemplo n.º 2
0
 void IDisposable.Dispose()
 {
     this.hdcSrc = null;
     try
     {
         // clean up
         GDI32.DeleteObject(this.hBitmap);
         this.hBitmap = new IntPtr();
     }
     catch (Exception)
     { }
 }
Exemplo n.º 3
0
 void IDisposable.Dispose()
 {
     this.hdcSrc = null;
     try
     {
         // clean up
         GDI32.DeleteDC(this.dc);
         this.dc = new IntPtr();
     }
     catch (Exception)
     { }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an Image object containing a screen shot of a specific window
        /// </summary>
        /// <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
        /// <returns></returns>
        public static Image Capture(IntPtr handle)
        {
            // get te hDC of the target window
            using (User32DeviceContext hdcSrc = new User32DeviceContext(handle))
            {
                Size size = GetSize(handle);

                using (GDI32DeviceContext hdcDest = new GDI32DeviceContext(hdcSrc))
                {
                    // create a bitmap we can copy it to,
                    // using GetDeviceCaps to get the width/height
                    using (GDI32HBitmap bmp = new GDI32HBitmap(hdcSrc, size))
                    {
                        bmp.Blit(hdcSrc, hdcDest);
                        return(bmp.GetImage());
                    }
                }
            }
        }
Exemplo n.º 5
0
 public GDI32HBitmap(User32DeviceContext hdcSrc, Size size)
 {
     this.hdcSrc  = hdcSrc;
     this.size    = size;
     this.hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc.DC, size.Width, size.Height);
 }
Exemplo n.º 6
0
 public GDI32DeviceContext(User32DeviceContext hdcSrc)
 {
     this.hdcSrc = hdcSrc;
     this.dc     = GDI32.CreateCompatibleDC(hdcSrc.DC);
 }