标题:VB.net用什么方法可以快速获取当前屏幕的所有像素rgb值,VB6.0可以用GetDIB ...
取消只看楼主
huangjunxing
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2014-8-13
结帖率:50%
 问题点数:0 回复次数:1 
VB.net用什么方法可以快速获取当前屏幕的所有像素rgb值,VB6.0可以用GetDIBits,那VB.net用什么函数呢
大家好,请教一下用什么方法可以快速获取当前屏幕的所有像素rgb值,VB6.0可以用GetDIBits,那用什么函数呢,谢谢
搜索更多相关主题的帖子: VB.net 像素 rgb VB6.0 函数 
2018-08-05 21:33
huangjunxing
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2014-8-13
得分:0 
回复 2楼 lgwd
你好,我用CopyFromScreen获得截图片,显示在picture控件里面,但是图片刷新的过程太耗时间, 就是这条语句非常耗费时间,picDest.Image = destImg'。差不多总占时间的一半,有什么办法提高速度吗,这是我的代码
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class Form1

    Dim ka As Integer
   


 


    Private Sub GetScreenColor(ByVal IntX1 As Int16, ByVal IntY1 As Int16, ByVal IntX2 As Int16, ByVal IntY2 As Int16)

        '创建一个位图
        Dim Img As New Bitmap(IntX2 - IntX1 + 1, IntY2 - IntY1 + 1, Imaging.PixelFormat.Format24bppRgb)
        Dim destImg As New Bitmap(IntX2 - IntX1 + 1, IntX2 - IntX1 + 1)
        '创建一个画图对象,并载入之前创建的位图
        Dim G As Graphics = Graphics.FromImage(Img)

        

        '截屏,前两个参数表示截屏起点,第三和第四为绘制图像的起点。
        G.CopyFromScreen(IntX1, IntY1, 0, 0, New Size(IntX2 - IntX1 + 1, IntY2 - IntY1 + 1))
        ' Me.PictureBox1.Image = CType(Img, Image)
        '释放画图对象
        G.Dispose()

        '从左到右,从上到下
        '将截取到的图片载入内存
        Dim sourceData As Imaging.BitmapData = Img.LockBits(New Rectangle(0, 0, Img.Width, Img.Height), Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format24bppRgb)
        Dim destData As BitmapData = destImg.LockBits(New Rectangle(0, 0, Img.Width, Img.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb)
        '获取首地址
        Dim pSource As IntPtr = sourceData.Scan0

        '计算字节总数
        Dim allBytes As Int32 = Math.Abs(sourceData.Stride) * Img.Height

        '存放颜色值的字节数组
        Dim rgbvalues(allBytes - 1) As Byte

        '从内存中读取字节数据
        Marshal.Copy(pSource, rgbvalues, 0, allBytes)
        Dim pDest As IntPtr = destData.Scan0
        Marshal.Copy(rgbvalues, 0, pDest, allBytes)
        '解锁
        Img.UnlockBits(sourceData)
        destImg.UnlockBits(destData)
        Img.Dispose()
        picDest.Image = destImg'显示图片的picture控件
    End Sub

   

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        GetScreenColor(0, 0, 500, 500)
        ka = ka + 1
        If ka = 500 Then'循环截屏500次
            
            Timer1.Enabled = False
        End If
        TextBox1.Text = ka
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = True
    End Sub
End Class
2018-11-28 17:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-489045-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.906026 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved