public static System.Windows.Media.Imaging.WriteableBitmap CaptureScreen()
{
IntPtr handle;
IntPtr bits;
int size;
DllImportCaller.lib.CaptureScreen(out handle, out size, out bits);
byte[] buffer = new byte[size];
MarshalBypass.Copy(bits, buffer, 0, size);
DllImportCaller.lib.DeleteObject(handle);
int bufferPos = 0;
for (int i = 0; i < 384000; i++)
{
// colors stored as BGR
int pixel = buffer[bufferPos++];
pixel |= buffer[bufferPos++] << 8;
pixel |= buffer[bufferPos++] << 16;
bmp.Pixels[i] = pixel;
}
return bmp;
}