Results 1 to 11 of 11
  1. #1
    Dead Bones Brook's Avatar
    Join Date
    Sep 2008
    Gender
    female
    Location
    On that seat right over there.
    Posts
    8,328
    Reputation
    858
    Thanks
    1,533
    My Mood
    Daring

    [Help]Detect a certain pixels color[Solved]

    How to detect a certain pixels color?
    (if that pixel is that color, then ...)

    Anyone?

  2. #2
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Dead Bones Brook View Post
    How to detect a certain pixels color?
    (if that pixel is that color, then ...)

    Anyone?
    There's a thread a few pages back to do with a Guitar Hero bot and I explain a way to get the pixels color on the screen and compare it to a certain color, let me get the link for you.

    https://www.mpgh.net/forum/33-visual-...-searcher.html

    There you go, scroll down a bit and you'll find my post.
    Last edited by Jason; 08-20-2010 at 06:57 PM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  3. The Following 2 Users Say Thank You to Jason For This Useful Post:

    Blubb1337 (08-20-2010),Dead Bones Brook (08-21-2010)

  4. #3
    Dead Bones Brook's Avatar
    Join Date
    Sep 2008
    Gender
    female
    Location
    On that seat right over there.
    Posts
    8,328
    Reputation
    858
    Thanks
    1,533
    My Mood
    Daring
    Quote Originally Posted by J-Deezy View Post


    There's a thread a few pages back to do with a Guitar Hero bot and I explain a way to get the pixels color on the screen and compare it to a certain color, let me get the link for you.

    https://www.mpgh.net/forum/33-visual-...-searcher.html

    There you go, scroll down a bit and you'll find my post.
    I read it, but I don't get it, sorry.

  5. #4
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Which part don't you get?



  6. #5
    Dead Bones Brook's Avatar
    Join Date
    Sep 2008
    Gender
    female
    Location
    On that seat right over there.
    Posts
    8,328
    Reputation
    858
    Thanks
    1,533
    My Mood
    Daring
    The part where he tells me what to do.

  7. #6
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Okay i'll go through each section in detail for you.

    First step. declarations:

    [php]
    Private Declare Function GetPixel Lib "Gdi32.dll" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
    Private Declare Function CreateDC Lib "Gdi32.dll" (ByVal driverName As String, ByVal deviceName As String, ByVal output As String, ByVal lpInitData As IntPtr) As IntPtr
    Private Declare Function DeleteDC Lib "Gdi32.dll" (ByVal dc As IntPtr) As Boolean

    Dim ScreenDC As IntPtr
    [/php]

    The GetPixel function gets the color of a pixel at the specified coordinates and stores it as an integer value. For this to work you need a device context ("ByVal hdc", in this case we use "ScreenDC" which we assign to the display of your monitor) It also needs an x and y coordinate to get the pixel from ("ByVal x As Integer, ByVal y As Integer")

    CreateDC creates a device context and DeleteDC deletes the device context. We need to get the DC of the display so we can scan it. On closing the program we need to release the DC.

    ScreenDC is a global variable of type "IntPtr", we'll assign this variable a value in the form_load event.

    Okay now that's declarations out of the way, now we need to get that value for ScreenDC

    [php]
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ScreenDC = CreateDC("DISPLAY", Nothing, Nothing, CType(Nothing, IntPtr))
    End Sub
    [/php]

    Essentially what this does is assign the variable "ScreenDC" the device context of the monitor's display ("CreateDC("DISPLAY".....)")

    Okay now we've got the ScreenDC, yay! Before we continue we have to remember to release the DC on form close so add this before we forget!

    [php]
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    DeleteDC(ScreenDC)
    End Sub
    [/php]

    This will release the device context specified by the variable "ScreenDC"

    Okay so we've got the ScreenDC, now we can set up a PixelScanner function, like so:

    [php]
    Function PixelScan(ByVal startX As Integer, ByVal startY As Integer, ByVal toX As Integer, ByVal toY As Integer, ByVal sColor As System.Drawing.Color)

    Dim thisPixel As Integer
    Dim PixelColor As System.Drawing.Color

    For x As Integer = startX To toX
    For y As Integer = startY To toY
    thisPixel = GetPixel(ScreenDC, x, y)
    PixelColor = ColorTranslator.FromOle(thisPixel)

    If PixelColor = sColor Then
    'do whatever you want when the color is found here.
    End If

    Next
    Next

    Return Nothing

    End Function
    [/php]

    Okay basically what this is doing:

    The function "PixelScan" accepts 5 arguments; "StartX", "StartY", "ToX", "ToY" and "sColor".

    Envision the area you're scanning as a big box, specified by the "StartX", "StartY", "ToX", "ToY" variables. The StartX and StartY values tell the function what location to start the scan from (i.e putting 0 for both StartX and StartY will start the scan at the top left corner of your screen. Now you need to tell it where to stop scanning for both the X and Y coords, that pretty much sets up your box. Now for the last argument "sColor", this is the color we are going to compare each pixel to (i.e the color you are searching for)

    Now for the main part of the function.

    Basically, to break this down into English terminology:

    For each value of X between the two coordinates of x specified by "StartX" and "ToX", get every Y coordinate specified between "StartY" and "ToY". Now you have 2 coordinates, x and y. Now we employ the "GetPixel" function to get the color at this x/y coordinate. Remember, GetPixel outputs an integer, not a System.Drawing.Color. This is why we use a ColorTranslator to translate this integer into a color we can compare with our argument "sColor".

    Because this is a for/next it will continue until all the pixels are scanned. Basically you have your first "For/Next" which is the x values. Contained in this is the For/Next for y values. Basically what this is saying is, get an x value between "StartX" and "ToX", for this x value check every y value. Once that is complete the next x value will be chosen and the process will continue until all pixels in the area are scanned.

    In that snippet i have included a
    [php]
    'do what you want to happen when the colors match here
    [/php]

    Basically I have said, if the color of the currently scanned pixel is the same as the color specified by the argument "sColor", do something.

    Okay now all you need to do is scan.

    The following snippet will scan your whole screen (remember, your screen resolution is the number of pixels across and up your monitor):

    [php]
    PixelScan(0, 0, My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height, Color.Blue)
    [/php]

    Basically this is saying start scanning at the point (0, 0) and continue the entire screen has been scanned, the color to compare to is the color blue, if this color is found the function will do whatever you've told it to do when this color is found. Note, you don't need to use "My.Computer.Screen.WorkingArea..." all the time, that's just a quick way to tell it to scan the entire width and height of your screen, you can specify exactly what section to scan by putting an integer value in there like :

    [php]
    PixelScan(100, 100, 200, 200, color.black)
    [/php]

    I hope this long ass post helps you out, took ages to type out haha.

    Good luck.
    Last edited by Jason; 08-20-2010 at 08:29 PM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  8. The Following 3 Users Say Thank You to Jason For This Useful Post:

    Blubb1337 (08-20-2010),Dead Bones Brook (08-21-2010),Newphag (08-20-2010)

  9. #7
    Newphag's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    Your ass
    Posts
    12
    Reputation
    29
    Thanks
    0
    My Mood
    Sleepy
    Thank you,

    is a lazy ass...so i have to do his work.
    He wants me to make prog that finds pokemon for him.


    It works somehow....but he says: can`t find CreateDC in DLL Gdi32.dll.
    How i fix?
    For the rest its works ok
    Last edited by Newphag; 08-20-2010 at 10:52 PM.

  10. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Newphag View Post
    Thank you,

    is a lazy ass...so i have to do his work.
    He wants me to make prog that finds pokemon for him.


    It works somehow....but he says: can`t find CreateDC in DLL Gdi32.dll.
    How i fix?
    For the rest its works ok
    There may be a problem with your Gdi32.dll...try this (add it above "Public Class Form1" or w/e)

    [php]
    Imports System.Runtime. InteropServices 'REMOVE THE SPACE, MPGH BLOCKS IT OTHERWISE
    [/php]

    Then put this with your other declarations (DeleteDC etc)

    [php]
    <DllImport("Gdi32.dll")> _
    Public Shared Function CreateDC(ByVal driverName As String, ByVal deviceName As String, ByVal output As String, ByVal lpInitData As IntPtr) As IntPtr
    End Function
    [/php]

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  11. The Following User Says Thank You to Jason For This Useful Post:

    Dead Bones Brook (08-21-2010)

  12. #9
    Newphag's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    Your ass
    Posts
    12
    Reputation
    29
    Thanks
    0
    My Mood
    Sleepy
    Okay thanks,
    It works fine now.

  13. #10
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Newphag View Post
    Okay thanks,
    It works fine now.
    Okay good good.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  14. The Following User Says Thank You to Jason For This Useful Post:

    Dead Bones Brook (08-21-2010)

  15. #11
    Dead Bones Brook's Avatar
    Join Date
    Sep 2008
    Gender
    female
    Location
    On that seat right over there.
    Posts
    8,328
    Reputation
    858
    Thanks
    1,533
    My Mood
    Daring
    Quote Originally Posted by Newphag View Post
    Thank you,

    is a lazy ass...so i have to do his work.
    He wants me to make prog that finds pokemon for him.


    It works somehow....but he says: can`t find CreateDC in DLL Gdi32.dll.
    How i fix?
    For the rest its works ok
    Hey, fuck you.
    Glad it works though.


    Thank you mr. helper, love you.

Similar Threads

  1. [Help] Changing Richtextbox's selection color. [solved]
    By alvaritos in forum Visual Basic Programming
    Replies: 5
    Last Post: 04-22-2011, 03:19 AM
  2. [Help]Portions of Screen Flash Diff. Colors[Solved
    By Balls Out in forum Battlefield Bad Company 2 (BFBC2) Hacks
    Replies: 7
    Last Post: 08-12-2010, 08:51 AM
  3. [Help]Change Txt Colors[Solved]
    By ppl2pass in forum Visual Basic Programming
    Replies: 4
    Last Post: 05-10-2010, 02:43 AM
  4. [help]Convert String to Color[Solved]
    By mnpeepno2 in forum Visual Basic Programming
    Replies: 10
    Last Post: 04-02-2010, 01:08 PM
  5. [Help]Form Background Color[Solved]
    By Shark23 in forum Visual Basic Programming
    Replies: 5
    Last Post: 03-08-2010, 10:34 PM