使用两个点捕获屏幕截图
本文关键字:屏幕截图 两个 | 更新日期: 2023-09-27 18:32:48
如何捕获一个截图给它两点,基本上创建一个矩形截图什么的?
我使用了这个:如何使用两个 PointF 创建一个矩形 F?
但它似乎没有得到我想要的矩形屏幕截图,它把我带到了屏幕的一角。
private void KListener_KeyDown(object sender, RawKeyEventArgs args)
{
if (args.Key.ToString() == "F5")
{
Program.FirstPos = System.Windows.Forms.Cursor.Position;
System.Media.SystemSounds.Asterisk.Play();
}
else if (args.Key.ToString() == "F6")
{
Program.SecondPos = System.Windows.Forms.Cursor.Position;
System.Media.SystemSounds.Asterisk.Play();
}
}
public Bitmap CaptureScreen()
{
RectangleF rect2 = GetRectangle(Program.FirstPos, Program.SecondPos);
var image = new Bitmap((int)rect2.Width, (int)rect2.Height, PixelFormat.Format24bppRgb);
var gfx = Graphics.FromImage(image);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
image.Save("C:''Users''DreTaX''Documents''teszt", ImageFormat.Jpeg);
return image;
}
gfx.CopyFromScreen(rect2.左,矩形2。顶部,0,0,图像。Size, CopyPixelOperation.SourceCopy);