形式保存为图像(截图) [英] Save form as image (screenshot)

查看:137
本文介绍了形式保存为图像(截图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2种形式。


  • 表1包含了我需要的截图内容

  • 表格2包含图形绘制(这种形式是总在最前面,但透明)。

我需要截屏的第一种形式,而不使其在形式2的顶部以及不包括形式2的内容。

I need to screen shot the first form without making it on top of form 2 as well as without including content from form 2.

这里是一些什么,我有工作,我正努力解决。

here is some what i am working with, which i am trying to fix.

Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
    Dim Screenshot As New Bitmap(Control.Width, Control.Height)
    Control.DrawToBitmap(Screenshot, New Rectangle(0, 0, Control.Width, Control.Height))
    Return Screenshot
End Function

此功能无法正常工作,因为Control.drawtoBitmap没有设置IMG的价值。

This function is not working because Control.drawtoBitmap is not setting the value of IMG.

IMG是空白并恢复为纯白色图像。

IMG is blank and being returned as a plain white image.

这个函数的调用是这样的。

The calling of this function is this

TakeScreenShot(form1.webbrowser1).Save("c:\Screenshot.png", 
     System.Drawing.Imaging.ImageFormat.Png)

所有的帮助将是AP preciated。

All help would be appreciated.

推荐答案

本替换你的 TakeScreenShot 功能:

Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
    Dim tmpImg As New Bitmap(Control.Width, Control.Height)
    Using g As Graphics = Graphics.FromImage(tmpImg)
        g.CopyFromScreen(Control.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(Control.Width, Control.Height))
    End Using
    Return tmpImg
End Function

这应该工作,但是,如果由于某种原因,它没有这个问题可能是在上面的透明状。搜索结果
你可以把它在excactly以同样的方式。搜索结果
祝你好运:)

This should work, however if for some reason it doesn't the problem might be the transparent form on top.

You can call it in excactly the same way.

Good luck :)

这篇关于形式保存为图像(截图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆