截取程序时截取屏幕截图 [英] Take a screenshot with program minimized

查看:78
本文介绍了截取程序时截取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为正在制作的程序编写了一些代码,以便在程序最小化时进行屏幕截图.代码有问题,我不确定它是什么.每当我拍摄屏幕截图时,程序都会在应用程序启动时拍照,而不是最小化.

I wrote some code for a program I am making to take a screenshot when the program is minimized. Thing is something is wrong with the code and I am not sure what it is. Whenever I take a screenshot the program is taking the picture with the application up and not minimized.

所以我需要做的是最小化应用程序,然后截取屏幕截图,然后在截取屏幕截图后重新打开程序.

So what I need it to do is minimize the application then take the screenshot and then reopen the program after its taken the screenshot.

很抱歉出现noob问题,但是我是VB的新手,只用了不到一天的时间就对它进行了编码.

Sorry for the noob question but I am brand new to the VB and only been coding it in for less then a day.

    Dim screenImage As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
    Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenImage)
    g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height))


    Me.Hide()
    screenImage.Save("C:\screenImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    Dim tSpan As TimeSpan = TimeSpan.FromSeconds(System.DateTime.Now.Second)
    Dim tSpan2 As TimeSpan = TimeSpan.FromSeconds(System.DateTime.Now.Second)
    Do While Math.Abs(tSpan.Subtract(tSpan2).Seconds) < 2
        tSpan2 = TimeSpan.FromSeconds(System.DateTime.Now.Second)

    Loop
    Me.Show()

任何帮助都会很棒.

推荐答案

您正在截屏后调用隐藏 :

尝试一下:

Dim screenImage As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenImage)

Me.Hide()
Me.Application.DoEvents() ' <-- might not be necessary; try without it first.

g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height))

screenImage.Save("C:\screenImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Dim tSpan As TimeSpan = TimeSpan.FromSeconds(System.DateTime.Now.Second)
Dim tSpan2 As TimeSpan = TimeSpan.FromSeconds(System.DateTime.Now.Second)
Do While Math.Abs(tSpan.Subtract(tSpan2).Seconds) < 2
    tSpan2 = TimeSpan.FromSeconds(System.DateTime.Now.Second)

Loop
Me.Show()

这篇关于截取程序时截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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