c# winforms:获取必须位于控件后面的屏幕截图图像
我有 C# Windows 窗体,上面有几个控件,部分控件一个接一个地位于另一个控件上。我想要一个函数,该函数将从表单中获取控件作为输入,并返回必须位于控件后面的图像。例如:如果表单具有背景图像并包含一个按钮 - 如果我运行此函数,我将获得位于按钮后面的背景图像部分。有什么想法和代码吗?
帮助!!!
I have c# windows form which have several controls on it, part of the controls are located one on another. I want a function that will take for input a control from the form and will return the image that has to be behind the control. for ex: if the form has backgroundimage and contains a button on it - if I'll run this function I'll got the part of backgroundimage that located behind the button. any Idea - and code?
H-E-L-P!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我最初的猜测,但必须进行测试。
重新建立按钮。
That's my initial guess, but have to test it.
Restablish button.
这很容易做到。窗体上的每个控件都有一个 Size 和一个 Location 属性,您可以使用它们实例化一个新的 Rectangle,如下所示:
要获取包含位于控件后面的背景图像部分的位图,您首先创建正确的尺寸:
然后为新的位图创建一个 Graphics 对象,并使用该对象的 DrawImage 方法复制背景图像的一部分:
这将为您留下包含该控件下方的背景图像部分的新位图 (bmp) 。
抱歉,我无法在代码中提供更具体的信息 - 我在公共终端。但智能感知信息会告诉您需要为 DrawImage 方法传入什么内容。
This is pretty easy to do. Each control on the form has a Size and a Location property, which you can use to instantiate a new Rectangle, like so:
To get a Bitmap that contains the portion of the background image located behind the control, you first create a Bitmap of the proper dimensions:
You then create a Graphics object for the new Bitmap, and use that object's DrawImage method to copy a portion of the background image:
This will leave you with the new Bitmap (bmp) containing the portion of the background image underneath that control.
Sorry I can't be more specific in the code - I'm at a public terminal. But the intellisense info will tell you what you need to pass in for the DrawImage method.