API function declaration
[System. runtime. interopservices. dllimportattribute ("gdi32.dll")]
Private Static extern bool bitblt (
Intptr hdcdest, // handle of the target device
Int nxdest, // X coordinate in the upper left corner of the target object
Int nydest, // X coordinate in the upper left corner of the target object
Int nwidth, // The width of the rectangle of the target object
Int nheight, // The length of the rectangle of the target object
Intptr hdcsrc, // Source Device handle
Int nxsrc, // X coordinate in the upper left corner of the source object
Int nysrc, // X coordinate in the upper left corner of the source object
System. int32 dwdrop // The operation value of the grating
);
[System. runtime. interopservices. dllimportattribute ("gdi32.dll")]
Private Static extern intptr createdc (
String lpszdriver, // driver name
String lpszdevice, // device name
String lpszoutput, // useless, can be set to "null"
Intptr lpinitdata // any printer data
);
Main Program:
Intptr DC1 = createdc ("display", null, null, (intptr) null );
Graphics G = graphics. fromhdc (DC1 );
Bitmap map = new Bitmap (system. Windows. Forms. Screen. primaryscreen. bounds. Width, system. Windows. Forms. Screen. primaryscreen. bounds. Height, G );
Graphics G1 = graphics. fromimage (MAP );
Intptr DC3 = G. gethdc ();
Intptr DC2 = g1.gethdc ();
Bitblt (DC2, 0, 0, system. windows. forms. screen. primaryscreen. bounds. width, system. windows. forms. screen. primaryscreen. bounds. height, DC3, 0, 0, 13369376 );
G. releasehdc (DC3 );
G1.releasehdc (DC2 );
String dt = datetime. Now. tostring ();
G1.drawstring (datetime. Now. tostring (), new font ("", 36), new solidbrush (color. Red), new point (430,330 ));
Try
{
Map. Save (@ "C:/inetpub/wwwroot/DW/aaa.jpg", system. Drawing. imaging. imageformat. JPEG );
}
Catch
{
}
Finally
{
Map. Dispose ();
GC. Collect ();
}