开发者

C# library to take screenshots?

开发者 https://www.devze.com 2023-01-16 14:08 出处:网络
Is there a good library I can use in c# to take a screenshot/snapshot? One where I can drag and drop a region of my screen, to take a screenshot/开发者_高级运维snapshot of it?I\'m not aware of any li

Is there a good library I can use in c# to take a screenshot/snapshot?

One where I can drag and drop a region of my screen, to take a screenshot/开发者_高级运维snapshot of it?


I'm not aware of any libraries that allow you to visually select a region on your screen, but a screenshot of your whole screen can be taken using the Graphics.CopyFromScreen method as follows:

var bounds = Screen.PrimaryScreen.Bounds;
using (var bmp = new Bitmap(bounds.Width,
                            bounds.Height,
                            PixelFormat.Format32bppArgb))
using (var gfx = Graphics.FromImage(bmp))
{
    gfx.CopyFromScreen(bounds.X,
                       bounds.Y,
                       0,
                       0,
                       bounds.Size,
                       CopyPixelOperation.SourceCopy);
    bmp.Save("shot.png");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消