【发布时间】:2016-01-31 16:47:25
【问题描述】:
我怎样才能捕获一个给它两个点的屏幕截图并基本上创建一个矩形屏幕截图或其他东西?
我用这个:How to create a RectangleF using two PointF?
但它似乎没有得到我想要的矩形屏幕截图,它把我带到了屏幕的角落。
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;
}
【问题讨论】:
-
您是否考虑了基于屏幕左上角的坐标。此外,向我们展示您迄今为止所写的内容将增加您获得帮助的机会。
-
你去。我所做的只是保存两个点(它们不同,我测试了它),然后使用该方法制作它的图像。
-
不要认为这会改变任何东西,但你的图像变量是一个位图,所以它可以是 'Bitmap image = ...' 并且 gfx 是 Graphics 类型,所以它可以是 'Graphics gfx = . ..' 运行代码时没有理由使用 var。设置 rect2 时,矩形位置的值是什么?
-
gfx.CopyFromScreen(rect2.Left, rect2.Top, 0, 0, image.Size, CopyPixelOperation.SourceCopy);看这里stackoverflow.com/questions/3306600/…
-
@Jacobr365 不管我是否使用内置类型都没有关系。我会在一秒钟内检查我们的那个。顺便说一句,这是我得到的图像:db.tt/GHmyfJ0S 所以第二个位置是完美的,但不知何故第一个坐标被颠倒了。它在反射
标签: c# screenshot