posts - 7,  comments - 3,  trackbacks - 0
[DllImport("coredll.dll", EntryPoint = "BitBlt")]
        
extern public static bool BitBlt(
                                    IntPtr hdcDest, 
// 目标 DC的句柄 
                                    int nXDest,
                                    
int nYDest,
                                    
int nWidth,
                                    
int nHeight,
                                    IntPtr hdcSrc, 
// 源DC的句柄 
                                    int nXSrc,
                                    
int nYSrc,
                                    RasterOperation dwRop 
// 光栅的处理数值 
        );
[DllImport(
"coredll.dll", EntryPoint = "GetDC")]
        
public static extern IntPtr GetDC(IntPtr hwnd);
//截取屏幕图像
        public static Image GetScreenShot()
        
{
            
try
            
{
                IntPtr srcHdc 
= GetDC(IntPtr.Zero);
                Rectangle rect 
= System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                Bitmap image 
= new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                
using (Graphics graphics = Graphics.FromImage(image))
                
{
                    IntPtr dstHdc 
= graphics.GetHdc();
                    BitBlt(dstHdc, 
00, image.Width, image.Height, srcHdc, 0,00x00CC0020);
                    graphics.ReleaseHdc(dstHdc);
                    
return image;
                }

            }

            
catch (System.Exception e)
            
{
                MessageBox.Show(e.Message, 
"GetScreenShot Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                
return null;
            }

        }
转自
http://www.devdiv.net/viewthread.php?tid=12128&extra=page%3D1%26amp%3Bfilter%3Dtype%26amp%3Btypeid%3D25
posted on 2009-09-04 16:33 老虎爱吃鱼 阅读(281) 评论(3) 编辑 收藏