• Log in or sign up for an account here: https://www.sythe.org/login

Image Recognition? VB 2010

master414

Active Member
Joined
Feb 26, 2006
Sythe Gold
0
Messages
214
Location
United Kingdom
Image Recognition? VB 2010
How do I make it so it detects any image on your screen, and finds the XY coordinates of it, then clicks on it?

Anyone have a video tutorial or source? I would even pay learning how this is done.


Edit: As an extra, how do you make hotkeys triggering a macro? So if I press Y for example, it'll press the following keys: A, B, C, F1, F2, ESC.
 
Image Recognition? VB 2010
Is it that difficult? I am willing to pay much $$$.
 
Image Recognition? VB 2010
I could make this program for you, but first i have to ask is it for a game or a webpage?
If it's a game can you give me a printscreen of what you will be trying to click.

As for the hotkeys look at the source in this thread:
http://sythe.org/showthread.php?t=1228818

There is also a colour clicker source there that may aid you into your image clicker as it uses the same principle.
 
Image Recognition? VB 2010
Here is some code in Delphi, can't remember if I wrote it or not, but it was in one of my old macro projects. Cruel may have written it, or a similar function, so I;m really not sure if I can take credit. its been years since I opened this

Code:
function FindBitmapBox(wHandle: HWND; xs,ys,xe,ye:integer; bitmap: Integer; var x, y: Integer; flag, tol, mask: Integer): Boolean;
var
  bmp1, bmp2: TBitmap;
  x1, y1, x2, y2, tmpColor, FirstColor: Integer;
  FirstPoint: TPoint;
  tmpDC: HDC;
  tmpRECT: TRect;
  p, p2, p3: PRGBArray;
label first, done, testy;
begin
  GetWindowRECT(wHandle, tmpRECT);
  //showmessage(inttostr(tmprect.top));
  tmpDC := getwindowdc(wHandle);
  bmp2 := TBitmap.Create;
  bmp2.Handle := bitmap;
  bmp1 := TBitmap.Create;
  bmp1.PixelFormat := pf24bit;
  bmp1.Width := tmpRECT.Right - tmpRECT.Left;
  bmp1.Height := tmpRECT.Bottom - tmpRECT.Top;
  BitBlt(bmp1.Canvas.Handle, 0, 0, xe - xs, ye - ys, tmpdc, xs, ys, SRCCOPY);
  //BitBlt(form1.image2.Canvas.Handle, 0, 0, xe - xs, ye - ys, bmp1.canvas.handle, 0, 0, SRCCOPY);
  bmp1.Height := ye - ys;
  bmp1.Width := xe - xs;
  releasedc(whandle,tmpDC);
  Result := True;
  FirstPoint.X := 0; FirstPoint.Y := 0;

  if mask >= 0 then begin
    for y1 := 0 to bmp2.Height - 1 do
      for x1 := 0 to bmp2.Width - 1 do
        if GetPixel(bmp2.Canvas.Handle, x1, y1) <> mask then begin
          FirstColor := GetPixel(bmp2.Canvas.Handle, x1, y1);
          FirstPoint.X := x1; FirstPoint.Y := y1;
          goto first;
        end;
    x := round(bmp2.Width / 2);
    y := round(bmp2.Height / 2);
    goto done;
  end;
  FirstColor := GetPixel(bmp2.Canvas.Handle, 0, 0);
  first:
 //showmessage(inttostr(FirstPoint.x));
  for y1 := 0 to bmp1.Height - 1 do begin
    p := bmp1.ScanLine[y1];
    for x1 := 0 to bmp1.Width - 1 do begin
      tmpColor := RGB(p[x1].b, p[x1].g, p[x1].r);
      if SimilarColors(tmpColor, FirstColor, tol) then begin
        for y2 := 0 to bmp2.Height - 1 do begin
          if y1 + y2 - FirstPoint.y > bmp1.height - 1 then goto testy;
          if y1 + y2 - FirstPoint.y < 0 then goto testy;
          p2 := bmp2.ScanLine[y2];
          p3 := bmp1.ScanLine[y1 + y2 - FirstPoint.y];
          for x2 := 0 to bmp2.Width - 1 do begin
            x := x1 + x2 - FirstPoint.X;
            tmpColor := RGB(p2[x2].b, p2[x2].g, p2[x2].r);
            if x > bmp1.Width - 1 then  goto testy;
            if x < 0 then goto testy;
            if mask < 0 then begin
              if not SimilarColors(tmpColor, RGB(p3[x].b, p3[x].g, p3[x].r), Tol) then goto testy;
            end else if tmpColor <> mask then if not SimilarColors(RGB(p3[x].b, p3[x].g, p3[x].r), tmpColor, Tol) then goto testy;
          end;
        end;
        //showmessage(inttostr(x1-firstpoint.X)+','+inttostr(y1-firstpoint.Y));
        x := xs + x1 - FirstPoint.x; y := ys  + y1 - FirstPoint.Y;
        if flag in [4, 5, 6] then y := y + ys + round(bmp2.Height / 2);
        if flag in [7, 8, 9] then y := y + ys + bmp2.Height;
        if flag in [2, 5, 8] then x := x + xs + round(bmp2.Width / 2);
        if flag in [3, 6, 9] then x := x + xs + bmp2.Width;
        goto done;
      end;
      testy:
    end;
  end;

  Result := False;
  done:
  bmp1.Free;
  bmp1 := nil;
  bmp2.ReleaseHandle;
  bmp2.Free;
  bmp2 := nil;
end;



Obviously you're going to have to translate some code, but it should be fairly easy considering how similar Delphi 7 and VB6 are. There is no scanline property in VB, so if you have any difficulties let me know and I can help.

and hey covey ;)
 
Image Recognition? VB 2010
Here is some code in Delphi, can't remember if I wrote it or not, but it was in one of my old macro projects. Cruel may have written it, or a similar function, so I;m really not sure if I can take credit. its been years since I opened this

Code:
function FindBitmapBox(wHandle: HWND; xs,ys,xe,ye:integer; bitmap: Integer; var x, y: Integer; flag, tol, mask: Integer): Boolean;
var
  bmp1, bmp2: TBitmap;
  x1, y1, x2, y2, tmpColor, FirstColor: Integer;
  FirstPoint: TPoint;
  tmpDC: HDC;
  tmpRECT: TRect;
  p, p2, p3: PRGBArray;
label first, done, testy;
begin
  GetWindowRECT(wHandle, tmpRECT);
  //showmessage(inttostr(tmprect.top));
  tmpDC := getwindowdc(wHandle);
  bmp2 := TBitmap.Create;
  bmp2.Handle := bitmap;
  bmp1 := TBitmap.Create;
  bmp1.PixelFormat := pf24bit;
  bmp1.Width := tmpRECT.Right - tmpRECT.Left;
  bmp1.Height := tmpRECT.Bottom - tmpRECT.Top;
  BitBlt(bmp1.Canvas.Handle, 0, 0, xe - xs, ye - ys, tmpdc, xs, ys, SRCCOPY);
  //BitBlt(form1.image2.Canvas.Handle, 0, 0, xe - xs, ye - ys, bmp1.canvas.handle, 0, 0, SRCCOPY);
  bmp1.Height := ye - ys;
  bmp1.Width := xe - xs;
  releasedc(whandle,tmpDC);
  Result := True;
  FirstPoint.X := 0; FirstPoint.Y := 0;

  if mask >= 0 then begin
    for y1 := 0 to bmp2.Height - 1 do
      for x1 := 0 to bmp2.Width - 1 do
        if GetPixel(bmp2.Canvas.Handle, x1, y1) <> mask then begin
          FirstColor := GetPixel(bmp2.Canvas.Handle, x1, y1);
          FirstPoint.X := x1; FirstPoint.Y := y1;
          goto first;
        end;
    x := round(bmp2.Width / 2);
    y := round(bmp2.Height / 2);
    goto done;
  end;
  FirstColor := GetPixel(bmp2.Canvas.Handle, 0, 0);
  first:
 //showmessage(inttostr(FirstPoint.x));
  for y1 := 0 to bmp1.Height - 1 do begin
    p := bmp1.ScanLine[y1];
    for x1 := 0 to bmp1.Width - 1 do begin
      tmpColor := RGB(p[x1].b, p[x1].g, p[x1].r);
      if SimilarColors(tmpColor, FirstColor, tol) then begin
        for y2 := 0 to bmp2.Height - 1 do begin
          if y1 + y2 - FirstPoint.y > bmp1.height - 1 then goto testy;
          if y1 + y2 - FirstPoint.y < 0 then goto testy;
          p2 := bmp2.ScanLine[y2];
          p3 := bmp1.ScanLine[y1 + y2 - FirstPoint.y];
          for x2 := 0 to bmp2.Width - 1 do begin
            x := x1 + x2 - FirstPoint.X;
            tmpColor := RGB(p2[x2].b, p2[x2].g, p2[x2].r);
            if x > bmp1.Width - 1 then  goto testy;
            if x < 0 then goto testy;
            if mask < 0 then begin
              if not SimilarColors(tmpColor, RGB(p3[x].b, p3[x].g, p3[x].r), Tol) then goto testy;
            end else if tmpColor <> mask then if not SimilarColors(RGB(p3[x].b, p3[x].g, p3[x].r), tmpColor, Tol) then goto testy;
          end;
        end;
        //showmessage(inttostr(x1-firstpoint.X)+','+inttostr(y1-firstpoint.Y));
        x := xs + x1 - FirstPoint.x; y := ys  + y1 - FirstPoint.Y;
        if flag in [4, 5, 6] then y := y + ys + round(bmp2.Height / 2);
        if flag in [7, 8, 9] then y := y + ys + bmp2.Height;
        if flag in [2, 5, 8] then x := x + xs + round(bmp2.Width / 2);
        if flag in [3, 6, 9] then x := x + xs + bmp2.Width;
        goto done;
      end;
      testy:
    end;
  end;

  Result := False;
  done:
  bmp1.Free;
  bmp1 := nil;
  bmp2.ReleaseHandle;
  bmp2.Free;
  bmp2 := nil;
end;



Obviously you're going to have to translate some code, but it should be fairly easy considering how similar Delphi 7 and VB6 are. There is no scanline property in VB, so if you have any difficulties let me know and I can help.

and hey covey ;)

Oh hullo joewnn :3 You should make a high pardon so you can come back and I don't have to ban you all the time
 
Runescape Gamblingrunescape gambling
Back
Top