[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int BitBlt(HandleRef hDC, int x, int y, int nWidth, int nHeight, HandleRef hSrcDC, int xSrc, int ySrc, int dwRop);

private void screenshut(int intx,int inty,int intwidth,int inthigh,int intleft,int intright)
{

DateTime ndate = new DateTime();
ndate = DateTime.Now;
string filename = ndate.ToFileTime().ToString();
filepath = @"c:\myresult\" + filename + ".bmp";

Rectangle rect = new Rectangle();

rect = this.Bounds;
Graphics g1 = this.CreateGraphics();
Bitmap mybmp = new Bitmap(intwidth, inthigh, g1);

Graphics g2 = Graphics.FromImage(mybmp);
IntPtr dc1 = g1.GetHdc();
HandleRef hdcsrc = new HandleRef(null, dc1);
IntPtr dc2 = g2.GetHdc();
HandleRef hdcsave = new HandleRef(null, dc2);

const int scrcop = 0xcc0020;
BitBlt(hdcsave, intx, inty, intwidth, inthigh, hdcsrc, intleft, intright, scrcop);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

mybmp.Save(filepath, ImageFormat.Bmp);

}

posted on 2024-04-20 22:13  Lionever  阅读(12)  评论(0)    收藏  举报