Results 1 to 1 of 1
  1. #1
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad

    C++ Pixel Scanner

    I wrote this and released it else where under a different name, but I never made use of it and neither did they so here you go :O Tool lazy to clean it up, although the code looks pretty neat already soh. Don't redistribute it in any form(be it compiled or not) without my permission. Under

    Header :
    [highlight=cpp]
    #ifndef PIXELSCANNINGWRAPPER_H_
    #define PIXELSCANNINGWRAPPER_H_
    #include <windows.h>
    struct Img
    {
    COLORREF crPixSearch[30][30];
    int iX,iY;
    int iWidth, iHeight;
    };

    struct Vector2D {
    int iX,iY;
    };

    struct Rect {
    int iX,iY,iWidth,iHeight;
    };

    Vector2D searchForImg(Img &Input, Rect &SearchBounds, float delay);
    HBITMAP getImage(LPCWSTR path, bool resource);
    int loadImage(Img &Input, HBITMAP &hBitmapSource,Rect rect, float delay);

    #endif
    [/highlight]
    Source File :
    [highlight=cpp]

    #include <windows.h>
    #include "pixelScanningWrapper.h"

    Vector2D searchForImg(Img &Input, Rect &SearchBounds, float delay) {
    HDC desktop = GetDC(HWND_DESKTOP);
    int yIndex, xIndex, pixelsMatched, rowsMatched;
    rowsMatched = pixelsMatched = yIndex = xIndex = 0;
    Vector2D retLoc;
    retLoc.iX = retLoc.iY = -1;

    bool imageFound = false;
    for(int y = SearchBounds.iY;; y++) {
    if(rowsMatched == Input.iHeight) {
    imageFound = true;
    break;
    }

    if(y > SearchBounds.iY + SearchBounds.iWidth)
    break;

    for(int x = SearchBounds.iX;; x++) {
    Sleep((DWORD)delay); //Typecast is to avoid warnings flagged by compiler
    if((x + Input.iWidth) > SearchBounds.iX + SearchBounds.iWidth)
    break;

    COLORREF pixel = GetPixel(desktop, x, y); //FIX ON RELEASE
    if(Input.crPixSearch[xIndex][yIndex] == pixel) {
    xIndex++;
    pixelsMatched++;
    }
    else{
    xIndex = 0;
    pixelsMatched = 0;
    }

    if(pixelsMatched == Input.iWidth) {
    if(rowsMatched == 0) {
    retLoc.iX = x - Input.iWidth;
    retLoc.iY = y;
    }else if(x - pixelsMatched != retLoc.iX) {
    rowsMatched = 0;
    break;
    }

    rowsMatched++;
    xIndex = pixelsMatched = 0;
    yIndex++;
    break;
    }
    }
    }

    if(!imageFound)
    retLoc.iX = retLoc.iY = -1;

    return retLoc;
    }

    HBITMAP getImage(LPCWSTR path, bool resource) {
    return (HBITMAP)LoadImage((HINSTANCE)GetModuleHandle(NULL ),
    path,
    IMAGE_BITMAP,
    0,
    0,
    LR_DEFAULTSIZE | (resource ? 0 : LR_LOADFROMFILE));
    }

    int loadImage(Img &Input, HBITMAP &hBitmapSource,Rect rect, float delay)
    {
    HDC hImage = 0;
    hImage = CreateCompatibleDC(0);

    if(!hImage)
    return -1;

    SelectObject(hImage, hBitmapSource);


    Input.iHeight = rect.iHeight;
    Input.iWidth = rect.iWidth;
    Input.iX = rect.iX;
    Input.iY = rect.iY;
    for(int Y = rect.iY;; Y++) {
    if(Y >= rect.iHeight)
    break;
    for(int X = rect.iX;; X++) {
    Sleep((DWORD)delay);
    if(X >= rect.iWidth)
    break;
    Input.crPixSearch[X][Y] = GetPixel(hImage, X, Y);

    }
    }
    return 1;
    }[/highlight]

    [b] I wrote this a while ago, I'm not doing it, but when you use this you should find problems(such as returning whole structs instead of pointers to them. So fix that.
    Last edited by NextGen1; 02-07-2011 at 06:10 PM.

Similar Threads

  1. Port Scanner
    By Vetu in forum Spammers Corner
    Replies: 8
    Last Post: 05-09-2016, 04:57 AM
  2. Virus Scanner
    By Elmo in forum Spammers Corner
    Replies: 9
    Last Post: 07-11-2010, 01:23 PM
  3. Human Pixels
    By arunforce in forum General
    Replies: 5
    Last Post: 07-15-2007, 12:55 AM
  4. Can anyone send me a virus scanner?
    By turbo159 in forum WarRock - International Hacks
    Replies: 4
    Last Post: 06-06-2007, 06:10 AM
  5. 2 Pixel Tutorial
    By Flawless in forum Tutorials
    Replies: 15
    Last Post: 02-21-2006, 02:53 PM

Tags for this Thread