Results 1 to 11 of 11

Thread: Counting bitmaps in an area

  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default Counting bitmaps in an area

    I'm having some trouble counting bitmaps within a specified X/Y region and I've tried everything I could think of, searched the forums for hours on end and still to no avail.

    1. I use Simba, not SCAR
    2. This is not for Runescape

    Here is a method by lordsaturn:
    SCAR Code:
    function FindBitmapsIn(bmp, x1, y1, x2, y2, Tol: integer): TPointArray;
    var
      x, y, bitmap, w, h, L, R, G, B: integer;
    begin
      w := x2 - x1;
      h := y2 - y1;
      bitmap := BitmapFromString(w, h, '');
      CopyClientToBitmap(bitmap, x1, y1, x2, y2);
      SetTargetBitmap(bitmap);
      while FindBitmapToleranceIn(bmp, x, y, 0, 0, w, h, Tol) do
      begin
        try
          if PointInTPA(Point(x, y), Result) then Break;
        except end;
        SetLength(Result, L+1);
        Result[L] := Point(x, y);
        Inc(L);
        ColortoRGB(FastGetPixel(bitmap, x, y), R, G, B);
        FastSetPixel(bitmap, x, y, RGBtoColor(iAbs(R-255), iAbs(G-255), iAbs(B-255)));
      end;
      FreeBitmap(bitmap);
      ResetDc;
    end;

    Maybe all I simply need is the Simba-equivalent to SCAR's 'ResetDc' method. Even with commenting out ResetDc I still have a flood of un-freed bitmaps, and to convert the result from this method to an integer I simply use something like this in another method: (This is just an example, not using real values)
    Simba Code:
    BitmapCount := High(FindBitmapsIn(BitMapID,500,300,600,400,25)):
    It's probably an obvious problem and an easy fix to most of you, but I'm still learning as I go so any ideas you can throw my way would be much appreciated.

  2. #2
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Why not just do:
    Simba Code:
    CountBitmaps: Integer;
    begin
      Result := Length(FindBitmaps);
    end;

    I left some parameters out though haha.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  3. #3
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

  4. #4
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Do you have the source for the FindBitmapsSpiralTolerance function?

    I don't see how you could call upon this method to return an integer, because this method itself returns as a statement?

    Has anyone used this particular method before? I'd sure love to see how they were able to use it.

  5. #5
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    https://github.com/MerlijnWajer/Simb...ore/finder.pas
    It doesn't return an integer, but you feed it a TPA, call the function, and then get the length of the TPA. Use the middle of x1,y1,x2,y2 for the x,y, unless you want to rewrite it to not use a spiral.

  6. #6
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Ha yeah I guess I still have alot to learn about Scar and Simba procedures, so thanks anyways for the help guys but I'm just not getting it and after hours of trying I'm giving up on using a simple formula, at this point I'll just make my own sloppy bitmap counter.

    Thanks for trying to help anyways.

  7. #7
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Does this work?
    Simba Code:
    if FindBitmapsSpiralTolerance(TheBitmap, (x1+x2)/2, (y1+y2)/2, TheTPA, x1, y1, x2, y2, TheTolerance) then
      BitmapCount := Length(TheTPA);

  8. #8
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    TPA would need to be the "Point(x,y)" in the center of the area you're searching for bitmaps, yes?

  9. #9
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    function FindBitmapsSpiralTolerance(bitmap: integer; x, y: Integer; var Points : TPointArray; xs, ys, xe, ye,tolerance: Integer): Boolean;

    bitmap: bitmap
    x, y : start of spiral (usually center of box) eg (x1+x2)/2, (y1+y2)/2
    Points: notice the var here (see also GetMousePos(var x, y)) this means you pass the function a variable, and it will write data to it. In this case, give it a blank TPA (declared without a length), and the function put in the top left corner of each occurrence of the bitmap it finds (ordered by distance from start of spiral).
    xs..... : box
    tol : bitmap tol

  10. #10
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Yes that did the trick. Boreas thank you so much for taking the time to help me out, it's very much appreciated!

    Before while trying to use FindBitmapsSpiralTolerance I had assumed the x/y were the x/y coordinates of each bitmap that was found within the area, therefore I defined the x and y as blank coordinates assuming they'd be defined when the bitmap(s) was found. From all the other usage of TPA's I've only seen them being used as already pre-defined, but using a blank TPA and letting the function find it according to the bitmaps's coordinates... that really saved my life.

  11. #11
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    You're welcome. More info on 'var' if your're interested:

    function Foo(var Bar:integer; OtherParam: boolean): string;

    MyStr := Foo(MyInt, MyBool);

    Foo can take input from MyInt and MyBool. It can give output to MyStr and MyInt.

    So var indicates you can read and write to a parameter. Usually supplied as a blank in finder functions like FindBitmapsSpiralTolerance (also important to declare arrays with dynamic length), or supplied as a full array in functions that rearrange the order*.

    *However some sorting functions do not use var so that they don't touch the supplied array, and instead return a new one, which is better in some situations.
    function SortArr(TheTPA: TPointArray): TPointarray;
    NewArr := SortArr(OldArr);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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