c# find color or image menu

Shout-Out

User Tag List

Results 1 to 5 of 5
  1. #1
    Bmbm873's Avatar Member
    Reputation
    1
    Join Date
    May 2007
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    c# find color or image

    okay im trying to do somthing quite simpel i am wanting to make c# find the color of a pizel on the screen and then move the mouse to that pixel how can i do this. I now how to do this in auto it and scar but not c# little help would go along way thank you
    Bishop Morley

    c# find color or image
  2. #2
    WhiteShizzle's Avatar Active Member
    Reputation
    17
    Join Date
    Jun 2008
    Posts
    248
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Bmbm873's Avatar Member
    Reputation
    1
    Join Date
    May 2007
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm maybe ill message with it some. if I dont get it in a while I might have to ask for help do you understand this stuff deathdude or are you just giving me this as a reference thank you already for your help though.

    If you do i might pm you a coupld questions thank you
    Bishop Morley

  4. #4
    Bmbm873's Avatar Member
    Reputation
    1
    Join Date
    May 2007
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay I found this on another webpage

    public static Point PixelSearch(Rectangle rect, int PixelColor, int Shade_Variation)
    {
    Color Pixel_Color = Color.FromArgb(PixelColor);

    Point Pixel_Coords = new Point(-1, -1);
    Bitmap RegionIn_Bitmap = CaptureScreenRegion(rect);
    BitmapData RegionIn_BitmapData = RegionIn_Bitmap.LockBits(new Rectangle(0, 0, RegionIn_Bitmap.Width, RegionIn_Bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

    int[] Formatted_Color = new int[3] { Pixel_Color.B, Pixel_Color.G, Pixel_Color.R }; //bgr

    unsafe
    {
    for (int y = 0; y < RegionIn_BitmapData.Height; y++)
    {
    byte* row = (byte*)RegionIn_BitmapData.Scan0 + (y * RegionIn_BitmapData.Stride);

    for (int x = 0; x < RegionIn_BitmapData.Width; x++)
    {
    if (row[x * 3] >= (Formatted_Color[0] - Shade_Variation) & row[x * 3] <= (Formatted_Color[0] + Shade_Variation)) //blue
    {
    if (row[(x * 3) + 1] >= (Formatted_Color[1] - Shade_Variation) & row[(x * 3) + 1] <= (Formatted_Color[1] + Shade_Variation)) //green
    {
    if (row[(x * 3) + 2] >= (Formatted_Color[2] - Shade_Variation) & row[(x * 3) + 2] <= (Formatted_Color[2] + Shade_Variation)) //red
    {
    Pixel_Coords = new Point(x + rect.X, y + rect.Y);
    goto end;
    }
    }
    }
    }
    }
    }

    end:
    return Pixel_Coords;
    }

    private static Bitmap CaptureScreenRegion(Rectangle rect)
    {
    Bitmap BMP = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb);
    Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
    GFX.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
    return BMP;
    }
    And it says it will do exactly what I want but I cant get it to work what includes should I add and how can I make it find the color and move my mouse to those coordinates thank you in advance im just not really having a good time with this lol
    Bishop Morley

  5. #5
    abuckau907's Avatar Active Member
    Reputation
    49
    Join Date
    May 2009
    Posts
    225
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need a couple API's:

    (vb.net code - sry )

    Code:
    //Move the Mouse
        Public Declare Function SetCursorPos Lib "user32.dll" (ByVal X As Int32, ByVal Y As Int32) As Boolean
    
    //Get Pixel Colors
        Declare Function GetPixel Lib "gdi32" (ByVal hDC As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
        Declare Function GetDesktopWindow Lib "user32" () As IntPtr
        Declare Function GetWindowDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr
        Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
    Code:
    Example:
        Public Function GetPixelColor(ByVal x As Int32, ByVal y As Int32) As Short()
    
            Dim hWnd As New IntPtr(0)
            Dim hDC As IntPtr
            hWnd = GetDesktopWindow()
            hDC = GetWindowDC(hWnd)
    
            Dim lColor As Int32 = GetPixel(hDC, x, y)
            ReleaseDC(hWnd, hDC)
            '' convert to rgb
            Dim rgbs(2) As Short
            rgbs(0) = ColorTranslator.FromWin32(lColor).R
            rgbs(1) = ColorTranslator.FromWin32(lColor).G
            rgbs(2) = ColorTranslator.FromWin32(lColor).B
            Return rgbs
        End Function
    GetPixel doesn't return a color in rgb format (not exactly..instead it returns a Int32 like 1234546.) There are better ways than returning it as an array..up to you to decide. --> Dim tCol As Color = ColorTranslator.FromWin32(lColor)
    return tCol;
    Last edited by abuckau907; 02-27-2010 at 04:24 PM.

Similar Threads

  1. [MPQ] How do I find the map image?
    By Tanaris4 in forum WoW Memory Editing
    Replies: 15
    Last Post: 09-28-2012, 01:34 PM
  2. Easy way to find real mage after mirror image
    By wootpeng in forum World of Warcraft Guides
    Replies: 5
    Last Post: 01-19-2009, 02:51 AM
  3. Replies: 0
    Last Post: 03-23-2008, 07:41 PM
All times are GMT -5. The time now is 06:13 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search