Added screenshot capabilities on F12.

This commit is contained in:
the_fiddler 2008-06-22 16:22:30 +00:00
parent 47bb81d62f
commit 49d1b68fa4

View file

@ -164,9 +164,31 @@ namespace Examples.Tutorial
PixelType.UnsignedByte, data.Scan0);
bitmap.UnlockBits(data);
}
#endregion Textures
#endregion Textures
Keyboard.KeyUp += KeyUp;
}
int i = 0;
void KeyUp(OpenTK.Input.KeyboardDevice sender, OpenTK.Input.Key e)
{
if (e == OpenTK.Input.Key.F12)
{
Bitmap bmp = new Bitmap(this.Width, this.Height);
System.Drawing.Imaging.BitmapData data =
bmp.LockBits(new Rectangle(0, 0, this.Width, this.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
GL.ReadPixels(0, 0, this.Width, this.Height,
OpenTK.Graphics.PixelFormat.Bgr,
OpenTK.Graphics.PixelType.UnsignedByte,
data.Scan0);
bmp.UnlockBits(data);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
bmp.Save("Screenshot" + (i++).ToString() + ".png", ImageFormat.Png);
}
}
#endregion
#region OnUnLoad
@ -219,7 +241,7 @@ namespace Examples.Tutorial
if (Keyboard[OpenTK.Input.Key.Escape])
{
this.Exit();
}
}
}
#endregion