英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论