如何把屏幕转换为Graphics对象啊

解决方案 »

  1.   

    IntPtr dc = GetDC(IntPtr.Zero);
    Graphics dcG = Graphics.FromHwnd(IntPtr.Zero);
    Bitmap bmp = new Bitmap(Width,Height,dcG);
    Graphics bmpG = Graphics.FromImage(bmp);
    IntPtr hdcDest = bmpG.GetHdc();
    BitBlt(hdcDest,0,0,bmp.Width,bmp.Height,dc,Left,Top,0x00CC0020);
    bmpG.ReleaseHdc(hdcDest);
    bmpG.Dispose();
    bmp.Save(@"c:\zlc.bmp",System.Drawing.Imaging.ImageFormat.Bmp);
    bmp.Dispose();
    dcG.Dispose();
    ReleaseDC(IntPtr.Zero,dc);
    api声明
    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    static public extern IntPtr GetDC(IntPtr hWnd); [DllImport("user32.dll", CharSet=CharSet.Auto)]
    static public extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

    [DllImport("gdi32.dll", CharSet=CharSet.Auto)]
    static public extern bool BitBlt(IntPtr hdcDest, // handle to destination device context 
    int nXDest, // x-coordinate of destination rectangle's upper-left corner
    int nYDest, // y-coordinate of destination rectangle's upper-left corner
    int nWidth, // width of destination rectangle 
    int nHeight, // height of destination rectangle 
    IntPtr hdcSrc, // handle to source device context 
    int nXSrc, // x-coordinate of source rectangle's upper-left corner  
    int nYSrc, // y-coordinate of source rectangle's upper-left corner
    uint dwRop); // raster operation code );
      

  2.   

    [ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
      private static extern IntPtr CreateDC (
       string lpszDriver , // 驱动名称
       string lpszDevice , // 设备名称
       string lpszOutput , // 无用,可以设定位"NULL"
       IntPtr lpInitData // 任意的打印机数据
       ) ;   //创建显示器的DC
       IntPtr dc1 = CreateDC ( "DISPLAY" , null , null , ( IntPtr ) null ) ;
       //由一个指定设备的句柄创建一个新的Graphics对象
       Graphics g1 = Graphics.FromHdc ( dc1 ) ;
      

  3.   

    ??——————————————————————————————————————
    资深C#专业QQ群组联盟,首群号11440220 ,汇集1000多位C#程序爱好者,欢迎加入,共同交流学习!支持论坛  www.Tushu.info
      

  4.   

    s5689412(华君) 谢了还有一个问题,获得了屏幕的Griphics,那怎么把屏幕上显示的东西转换层Bitmap???
      

  5.   

    靠,我贴的代码里面获得屏幕句柄和存储为图像的代码都有,bs你一下,sb!!!
      

  6.   

    -_-||  你当我没有试过你的代码啊,哪里是什么屏幕句柄,整的保存就是一个Form窗体