如何通过给定两个点来截取屏幕并创建矩形截图或其他内容?
我使用了这个链接: 如何使用两个PointF创建RectangleF?
但是它似乎没有得到我想要的矩形截图,而是把屏幕的角落给我了。
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;
}