どのように私は、画面から写真を撮ることができますか?
-
26-09-2019 - |
質問
私は...他の人に番組1台のPCの画面というプレゼンテーションシステムのようなものがプログラムを書きたいです。どのように私は、現在の画面から写真を撮ることができますか?
解決
.NETは画面を経由して、この機能を公開(ののSystem.Windows.Forms の)クラスます。
// the surface that we are focusing upon
Rectangle rect = new Rectangle();
// capture all screens in Windows
foreach (Screen screen in Screen.AllScreens)
{
// increase the Rectangle to accommodate the bounds of all screens
rect = Rectangle.Union(rect, screen.Bounds);
}
// create a new image that will store the capture
Bitmap bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
// use GDI+ to copy the contents of the screen into the bitmap
g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
}
// bitmap now has the screen capture
所属していません StackOverflow