WinCE 上截图

核心代码如下:

 

using  System;

using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;
using  System.Runtime.InteropServices;

namespace  Capture
{
    
public   partial   class  Form1 : Form
    {
        [DllImport(
" coredll.Dll " )]

        
private   static   extern  IntPtr CreateDC(
            
string  lpszDriver,  //  驱动名称 
             string  lpszDevice,  //  设备名称 
             string  lpszOutput,  //  无用,可以设定位"NULL" 
            IntPtr lpInitData  //  任意的打印机数据 
            );
        [DllImport(
" coredll.Dll " )]
        
private   static   extern   bool  BitBlt(
            IntPtr hdcDest, 
            
int  nXDest, 
            
int  nYDest, 
            
int  nWidth, 
            
int  nHeight, 
            IntPtr hdcSrc, 
            
int  nXSrc, 
            
int  nYSrc, 
            Int32 dwrop
            );

        
private   const   int  SRCCOPY   = 0xCC0020 ;

        
public  Form1()
        {
            InitializeComponent();
        }

        
private   void  button1_Click( object  sender, EventArgs e)
        {
            
int  iHeight  = Screen.PrimaryScreen.Bounds.Height;
            
int  iWidth  =  Screen.PrimaryScreen.Bounds.Width;
            IntPtr dc1 
=  CreateDC( null null null , (IntPtr) null );
            Graphics gScreen 
=  Graphics.FromHdc(dc1);
            Image iGetPhoto 
=   new  Bitmap(
                iWidth
                ,iHeight );
            Graphics gPhoto 
=  Graphics.FromImage(iGetPhoto);
            IntPtr iHandle 
=  gScreen.GetHdc();
            IntPtr iPhoto 
=  gPhoto.GetHdc();

            BitBlt(iPhoto, 
0 0 , iWidth, iHeight,
                iHandle, 
0 0 , SRCCOPY);
            gScreen.ReleaseHdc(iHandle);
            gPhoto.ReleaseHdc(iPhoto);
            iGetPhoto.Save(
@" \NandFlash\ice.bmp " ,System.Drawing .Imaging .ImageFormat .Bmp );
            iGetPhoto .Dispose ();

        }
    }
}

 

 

你可能感兴趣的:(WinCE)