如何设置屏幕截图的正确点或位置。

huangapple go评论165阅读模式
英文:

Vb.net How to set correct point or location of the screen for screen shot

问题

我正在尝试在我的应用程序中进行屏幕截图,请参考下面带有红色标记的图片:

如何设置屏幕截图的正确点或位置。

但它只捕获了这部分:

如何设置屏幕截图的正确点或位置。

顺便附上代码:

Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
    Dim screenSize As Size = New Size(Control.Width, Control.Height)
    Dim screenGrab As New Bitmap(Control.Width, Control.Height)
    Dim g As Graphics = Graphics.FromImage(screenGrab)
    g.CopyFromScreen(New Point(Control.Location.X, Control.Location.Y), Point.Empty, screenSize)
    Return screenGrab
End Function
英文:

I am trying to screen capture in my application please refer with the picture below that has red mark

如何设置屏幕截图的正确点或位置。

but it only captures this part

如何设置屏幕截图的正确点或位置。

here is the code by the way

Private Function TakeScreenShot(ByVal Control As Control) As Bitmap

    Dim screenSize As Size = New Size(Control.Width, Control.Height)

    Dim screenGrab As New Bitmap(Control.Width, Control.Height)

    Dim g As Graphics = Graphics.FromImage(screenGrab)

    g.CopyFromScreen(New Point(Control.Location.X, Control.Location.Y), Point.Empty, screenSize)

    Return screenGrab

End Function

答案1

得分: 2

This:

g.CopyFromScreen(New Point(Control.Location.X, Control.Location.Y), Point.Empty, screenSize)

should be this:

g.CopyFromScreen(Control.PointToScreen(Point.Empty), Point.Empty, screenSize)

PointToScreen will convert between the control's coordinate system and screen coordinates. Point.Empty is the origin in any control's coordinate system. This:

Control.PointToScreen(Point.Empty)

is equivalent to this:

Control.Parent.PointToScreen(Control.Location)
英文:

This:

g.CopyFromScreen(New Point(Control.Location.X, Control.Location.Y), Point.Empty, screenSize)

should be this:

g.CopyFromScreen(Control.PointToScreen(Point.Empty), Point.Empty, screenSize)

PointToScreen will convert between the control's coordinate system and screen coordinates. Point.Empty is the origin in any control's coordinate system. This:

Control.PointToScreen(Point.Empty)

is equivalent to this:

Control.Parent.PointToScreen(Control.Location)

huangapple
  • 本文由 发表于 2023年4月13日 15:52:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76002945.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定