屏幕闪烁时通知VB.Net

时间:2019-05-03 14:00:03

标签: vb.net visual-studio

我希望在屏幕开始闪烁时触发通知。该通知目前可以是一个msgbox,但我最终会将其演变为可听见的声音。

这样做的目的是我们有一个仪表板,可以显示整个公司的各个单元。当单元需要帮助时,其在仪表板上的位置将开始闪烁。像这样将这些单元格显示在水平堆叠的框中;


单元格1


单元2


单元3


等等...


我想构建一个扫描屏幕,每秒说一次并获取每个单元像素强度的应用程序。

如果/当单元像素强度在连续三次连续扫描中改变每次扫描时(即该单元必须闪烁),将触发通知。

我希望你们能帮助我找到一种扫描屏幕的方法,并返回区域平均像素强度,然后我可以将其复制并进行比较,以查看其是否闪烁。

谢谢您,我正在使用VB.Net。

1 个答案:

答案 0 :(得分:1)

我可以使用以下命令完成我的要求:

 Private Sub AvgColors(ByVal InBitmap As Bitmap)
        Dim btPixels(InBitmap.Height * InBitmap.Width * 3 - 1) As Byte
        Dim hPixels As GCHandle = GCHandle.Alloc(btPixels, GCHandleType.Pinned)
        Dim bmp24Bpp As New Bitmap(InBitmap.Width, InBitmap.Height, InBitmap.Width * 3,
          Imaging.PixelFormat.Format24bppRgb, hPixels.AddrOfPinnedObject)

        Using gr As Graphics = Graphics.FromImage(bmp24Bpp)
            gr.DrawImageUnscaledAndClipped(InBitmap, New Rectangle(0, 0,
              bmp24Bpp.Width, bmp24Bpp.Height))
        End Using

        Dim sumRed As Int32
        Dim sumGreen As Int32
        Dim sumBlue As Int32

        For i = 0 To btPixels.Length - 1 Step 3
            sumRed += btPixels(i)
            sumGreen += btPixels(i + 1)
            sumBlue += btPixels(i + 2)
        Next
        hPixels.Free()
        Dim avgRed As Byte = CByte(sumRed / (btPixels.Length / 3))
        Dim avgGreen As Byte = CByte(sumGreen / (btPixels.Length / 3))
        Dim avgBlue As Byte = CByte(sumBlue / (btPixels.Length / 3))


        MsgBox(avgRed & vbCrLf & avgGreen & vbCrLf & avgBlue)
    End Sub

    Private Function Screenshot() As Bitmap
        Dim b As Bitmap = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)

        Using g As Graphics = Graphics.FromImage(b)
            g.CopyFromScreen(0, 0, 0, 0, b.Size, CopyPixelOperation.SourceCopy)
            g.Save()
        End Using

        Return b
    End Function

从这里,我可以将位图的范围调整到我需要的范围,添加一个计时器以每秒滴答,并保留一个变量以比较平均RGB。

从此处找到的大多数代码:

http://www.vbforums.com/showthread.php?776021-RESOLVED-Getting-Average-RGB-Color-Value-of-Entire-Screen

相关问题