Results 1 to 7 of 7

Thread: [2005] Get a Pixel Color of a point in a screen

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    [2005] Get a Pixel Color of a point in a screen

    Hi!!

    I want to get the pixel color of the screen, in determinated point. I'm correnctly taking a screenshot and getting the information from there, but that takes a lot of time, and i need to have the information every 10 ms without putting to much load on the cumputer. Can you help me?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2005] Get a Pixel Color of a point in a screen

    Code:
    Dim c as Color
    c = Image.GetPixel(x, Y)
    Should be as simple as that

  3. #3

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2005] Get a Pixel Color of a point in a screen

    just one problem. Where u put Image. that image was to refer to the screen image.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2005] Get a Pixel Color of a point in a screen

    Replace file here with the path to your screen shot taken

    Code:
    Dim bitmap As New Bitmap("file here")
    Dim c As Color = bitmap.GetPixel(x, y)

  5. #5

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2005] Get a Pixel Color of a point in a screen

    that i know how to do! Let me explain better:
    If u dont have any window open u just see ur windows background image (wallpaper), if you have lets Firefox open u see the colors of the site you are in, right?

    Well i want to get the pixel color of the point x, y of the screen. The screen here means whatever you have top most in that point in windows. I hope i explained well now
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  6. #6
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    Re: [2005] Get a Pixel Color of a point in a screen

    Bump, I've been needing the same thing for centuries, just never found out how. I wonder it it's even possible to do? Is there a class to get the current screen as a bitmap and then do the pixel analysis?

  7. #7
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [2005] Get a Pixel Color of a point in a screen

    When you want to do something impossible in GDI+, use the Graphics.CopyFromScreen method. (The first argument, Source, is the screen coordinate of the point you want to capture, and the second one, Destination, is the graphics coordinate of where you want to copy the point to. They forgot to tell you that in the help files.)

    Here's a little working example I rustled up on a default Form. It reports the ARGB color value of any point on the screen in the Form's title bar. This technique captures only a single pixel, so probably it won't add too much CPU load. On my system it reports a CPU usage ranging from 2 to 8% when running from VS2008 Express.

    Code:
    Public Class Form1
    
        Private WithEvents timer1 As New Windows.Forms.Timer
    
        Private Sub Form1_Load(ByVal sender As System.Object, _
                        ByVal e As System.EventArgs) Handles MyBase.Load
    
            timer1.Interval = 10
            timer1.Start()
    
        End Sub
    
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, _
                        ByVal e As System.EventArgs) Handles timer1.Tick
    
            Using bmp As New Bitmap(1, 1)
                Using g As Graphics = Graphics.FromImage(bmp)
                    g.CopyFromScreen(Windows.Forms.Cursor.Position, _
                                              New Point(0, 0), New Size(1, 1))
                End Using
                Me.Text = bmp.GetPixel(0, 0).ToString
                Me.Invalidate()
            End Using
           
        End Sub
    
    End Class


    all the best, BB
    Last edited by boops boops; Nov 11th, 2008 at 06:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width