1. Ultimate Bitmap Tutorial!

Welcome to my bitmap tutorial. I will explain to you what bitmaps are, what they can be used for and how the can be used. This tutorial has been edited to work with Simba.

A bitmap is a picture (.bmp), which can be stored as a string in Simba and can be used for whatever reason.

I will teach you how to use bitmaps in 5 easy to understand steps.

Step 1. Creating the bitmap.

First off, click the printscreen button (Left to the scroll lock button). This will take a picture of your screen and save it to your clipboard. Open the run dialog by pressing Windows key + R then typing in mspaint

When paint opens, click Ctrl + V to paste the screenshot. Using the "select" tool drag your mouse over the image that you want to create a bitmap of. When that's done, right click then press cut. Click File > New then when the dialog box comes up asking you to save click No.

In your new canvas, click Ctrl + V again and the bitmap will be pasted into paint. Zoom in as much as you can, and crop it with the select tool a bit more until you have it perfect. It should look something like this

Click File > Save then make sure you select 24 Bitmap

To load the bitmap into the memory you have to use the function BitmapFromString

Simba Code:
BitmapFromString(Width, Height: Integer; data: string);

Lets say for example we wanted to find a bitmap of a copper ore.

When creating a bitmap you should not create it like the above picture. It should look like the picture below.

Now you have to declare a new variable which is an integer, and call it anything, in this case I will call it copperore. Everything the bitmap contains will be stored in this integer, which we will later use to find the bitmap.

Simba Code:
Program new;Var  copperore:Integer;BeginEnd.

We can then set copper to be the bitmap by using

Simba Code:
copperore := BitmapFromString(10, 11, 'beNoLVPZwMGFgYASi7Rl6p4' +'qNIAgiAkFlzrIrE7SQRQwUFCAIyG70VNiSrgvUuzhWEy4FNBN ibLe' +'/ElB2f67BoTyDTak6QBGIFER2SogqUBZo3ZkS4/Nlxnuz9eEKgIy5' +'UeoQ2WtVpjerzYDoeCHCYWuStIHqgbru1ZnfrjUHygLZQAVAu 4CyQ' +'I1AG4EiQCkgApoAZB8tMISYDySByoCWAsWBslcqTYFsoGCRow w8NI' +'BGAcWBxgJJIDfZQqLKVQ7ISPAzSwu2AjKABgJl4UHUBwA9B16 H');

To do this, open Simba then click Tools > Bitmap Conversion.

In the dialog box click Open then load the .bmp file. When you click "To string" you will get the bitmap printed into the debug box. I will show you how to use this.

Step 3. Finding the bitmap

There are many ways to find a bitmap and I will go through the ones most commonly used.

Lets make a procedure that load the bitmap into the memory.

Simba Code:
Procedure FindCopper;Var //Variables are declared herecopper, X, Y:Integer; //Declare bitmaps as IntegersBegincopper := BitmapFromString(10, 11, 'beNoLVPZwMGFgYASi7Rl6p4' +'qNIAgiAkFlzrIrE7SQRQwUFCAIyG70VNiSrgvUuzhWEy4FNBN ibLe' +'/ElB2f67BoTyDTak6QBGIFER2SogqUBZo3ZkS4/Nlxnuz9eEKgIy5' +'UeoQ2WtVpjerzYDoeCHCYWuStIHqgbru1ZnfrjUHygLZQAVAu 4CyQ' +'I1AG4EiQCkgApoAZB8tMISYDySByoCWAsWBslcqTYFsoGCRow w8NI' +'BGAcWBxgJJIDfZQqLKVQ7ISPAzSwu2AjKABgJl4UHUBwA9B16 H');If (FindBitmap(copper, X, Y)) Then //This will search the screen for the bitmapWriteln('Found the copper bitmap') //Tells us it found itElseWriteln('Could not find copper'); //Tells us we didn't find itEnd;

Just a quick run down of some commonly used bitmap functions.

**The greater colour range you want, the higher the tolerance parameter should be.

Simba Code:
FindBitmap(copper, X, Y);
This is the simplest way to search for a bitmap.

Simba Code:
FindBitmapTolerance(copper, X, Y, 15);
This works just like FindBitmap except you can add some tolerance. I made it 15.

Simba Code:
FindBitmapIn(copper, X, Y, 0, 0, 100, 100);
This will search for the bitmap in a defined area of your screen. In this example it will search for the bitmap from 0, 0 to 100, 100

Simba Code:
FindBitmapToleranceIn(copper, X, Y, 0, 0, 100, 100, 15);
This is FindBitmapTolerance and FindBitmapIn put together.

Simba Code:
FindBitmapSpiral(copper, 50, 50, 0, 0, 100, 100);
This will search for the bitmap from 0, 0 to 100, 100 but starting at 50, 50 (X, Y) and looking outwards from there.

Simba Code:
FindBitmapSpiralTolerance(copper, 50, 50, 0, 0, 100, 100, 15);
Works like FindBitmapSpiral but you can add tolerance.

Simba Code:
FindBitmapRotated(copper, 50, 50, 360, 0, 0, 100, 100);
Works like FindBitmap, but rotates the bitmap after each search by 1 degree. You most likely won't need to use this unless you are finding something that rotates. Will keep rotating until it reaches the angle you define, i set it to 360 so it rotates fully.

Step 4. Clicking the bitmap.

Have the variables ready and the bitmap loaded then we can start to click the bitmap.

How it works: Simba will search the area you define and if it finds the bitmap, it will set the coords of it into the X, Y (Which is why you set these to variables/integers). By using SRL's Mouse function it clicks the X, Y coordinates which is why it is termed "Clicking the bitmap". Example:

Simba Code:
Procedure FindCopper;{.Include SRL/SRL.scar} //This will add the SRL include to SimbaVar //Variablescopper, X, Y:Integer; //Declare bitmaps as IntegersBegin  SetupSRL; //This sets up SRL  copperore := BitmapFromString(10, 11, 'beNoLVPZwMGFgYASi7Rl6p4' +    'qNIAgiAkFlzrIrE7SQRQwUFCAIyG70VNiSrgvUuzhWEy4FNBN ibLe' +    '/ElB2f67BoTyDTak6QBGIFER2SogqUBZo3ZkS4/Nlxnuz9eEKgIy5' +    'UeoQ2WtVpjerzYDoeCHCYWuStIHqgbru1ZnfrjUHygLZQAVAu 4CyQ' +    'I1AG4EiQCkgApoAZB8tMISYDySByoCWAsWBslcqTYFsoGCRow w8NI' +    'BGAcWBxgJJIDfZQqLKVQ7ISPAzSwu2AjKABgJl4UHUBwA9B16 H');  If (FindBitmapToleranceIn(copperore, X, Y, 0, 0, 100, 100, 25)) Then //This will search the screen for the bitmap  Mouse(X, Y, 5, 5, True); //Clicks on the copper bitmap if found with a randomness of 5End.

Step 5. Freeing the bitmap from the memory.

After you use a bitmap (even if it doesn't find it) you should always free the bitmap. It's very simple to use:

Simba Code:
FreeBitmap(copper);

And that's it. Make sure you put this line after all the finding bitmap and clicking script.

Simba Code:
If (FindBitmapToleranceIn(copper, x, y, 0, 0, 100, 100, 25)) ThenBegin  Writeln('Found the copper bitmap') //Tells us it found it  Mouse(X, Y, 5, 5, true); //Clicks the bitmap with a randomness of 5, 5  FreeBitmap(copper); //This then frees the bitmapEnd;

In English: You call the bitmap and then click it, but if you don't free it, it will just stay in the memory doing nothing. When you call this bitmap again, it loads into the memory again and after a while simba will crash or stop working because of a memory leak, so it is VERY important to free it.

There are some good ways to use more advanced bitmaps and they come in good use too. They are very easy to use just follow this guide and if you need any help or have any problems please post in this thread.

Simba Code:
FindDeformedBitmapToleranceIn(copper, x, y, 0, 0, 100, 100, 25, 0, false, A);

What this function does, is it looks for a bitmap but skips any part that has the colour of 0 (Black). This is great if the background of the item changes so the script will always find the bitmap.

If we wanted to use FindDeformedBitmapToleranceIn to look for some iron ore, this is what you have to do.

After creating the bitmap, it will look like this.

This is pretty big and has some colours in it that do not need to be used. So using paint, colour in any part of the bitmap black that you do not want the script to look for so it looks like this.

You must remember never to use the whole item as a bitmap, only use part of it.

Now lets say we wanted to find the last picture we can set up the function like this:

Simba Code:
FindDeformedBitmapToleranceIn(IronOre, X, Y, 0, 0, 100, 100, 30, 0, false, acc);

The last 3 parts of this are Range, AllowPartialAccuracy and accuracy. If range is 0 (Which it should be on), it checks pixels at positions that match bitmap we are looking for. If the range is 1, it will check the pixels around the bitmap, if range is bigger, it checks further.

AllowPartialAccuracy allows accuracy that is not a 100% match. This should be set to false. Accuracy returns accuracy of found bitmap to bitmap we are looking for. Put in something such as "acc" or even "a" and declare it as an Extended. (An extended is a variable that can hold decimal places)

Simba Code:
VarA:Extended;

Simba Code:
RotateBitmap(iron, 3.14);

This basically just rotates the bitmap if you ever need to, but to be honest I have never needed to use this function.To make is rotate the bitmap 180 degrees set the value to 3.14 (Which is the value of Pi)

If you need any help with bitmaps or have any problems, please post in this thread and please state what you need help with
Last edited by cycrosism; 04-03-2013 at 02:29 PM.

2. Well explained tutorial, good work
Keep it up!

3. Yeah I guess I could a bit later, I was just running through some of the main ones

4. nice little refresher i almost forgot about bitmaps.

5. SRL Member
Join Date
Jun 2006
Posts
1,493
Mentioned
0 Post(s)
Quoted
0 Post(s)
You might also want to mention that you have to fill the background in with black

6. you dont need to do that if your just doing a peice of the bitmap :P like the copper ore example

7. SRL Member
Join Date
Jun 2006
Posts
1,493
Mentioned
0 Post(s)
Quoted
0 Post(s)
But the way you're doing it now, it will also look for the inventory background color.

I guess it doesn't matter if you are simply planning on using the bitmap for the inventory. But it's probably better practice to make them usable everywhere.

8. SRL Member
Join Date
Mar 2007
Location
DK
Posts
43
Mentioned
0 Post(s)
Quoted
0 Post(s)
Good work

9. Okay I added a few "advanced bitmaps" if anyone needs help with any thing to do with bitmaps please just post here and I will help you

10. SRL Junior Member
Join Date
Mar 2009
Location
Antaractica, Penguin Drive
Posts
140
Mentioned
0 Post(s)
Quoted
0 Post(s)
Good job Cycro :P

I never knew you could find deformed bitmaps lol

11. bump ^_^

12. Deformed method is slightly slower.

13. Yes it will take a bit longer to find the bitmap if you make the Boolean in FindDeformedBitmapToleranceIn true because it will alter the bitmap and make it bigger/smaller and try to search for it so yeah that might take a little bit longer to find

14. I love you? ^_^
One question, does bit maps click in the center of the bitmap (assuming you didn't set randoms)? or any where on it?

15. No it wont click on the center of the bitmap, but you can make it.

If the bitmap size is lets just say 14, 14 then do

Mouse(X+(7), Y+(7), 0, 0, True);

And that will click in the middle of it. If you dont it will click the bitmap on the top left corner of where it finds it

16. Retired Developer
Join Date
Mar 2007
Posts
4,814
Mentioned
3 Post(s)
Quoted
3 Post(s)
Originally Posted by cycrosism
No it wont click on the center of the bitmap, but you can make it.

If the bitmap size is lets just say 14, 14 then do

Mouse(X+(7), Y+(7), 0, 0, True);

And that will click in the middle of it. If you dont it will click the bitmap on the top left corner of where it finds it
Or you could use GetBitmapSize(Bitmap, W, H); and find the middle of that via shr 1 (which is basically '/ 2').

Example:

SCAR Code:
If FindBitmap(Bit, x, y) ThenBegin    GetBitmapSize(Bit, W, H);  Middle := Point(x + w shr 1, y + h shr 1);  Mouse(Middle.x, Middle.y, 0, 0, True);End;

That will work is you have variables 'w' and 'h' as integers and 'Middle' as a TPoint.

Great tutorial, Rep+

17. thanks ^^

18. I might add a guide on how to make bitmaps in Ubuntu, i'm not sure if I should do it because I don't know how many people here use Ubuntu

19. SRL Junior Member
Join Date
May 2008
Location
Posts
664
Mentioned
0 Post(s)
Quoted
6 Post(s)
Wait... what happened to your tutorial??? =[

20. People insulted him so he was going to quit and deleted all of his tutorials.
The reason why me made these tutorials was a tut cup and he didn't get it so...

21. SRL Junior Member
Join Date
May 2008
Location
Posts
664
Mentioned
0 Post(s)
Quoted
6 Post(s)
ah. i should've looked before asking. :\.

Comon cycro, don't deny us the priveledge of our education here...

22. My tutorial has been restored, Enjoy!

23. If anyone wants things added to this tutoral, post here or PM me and I will update it.

24. SRL Junior Member
Join Date
Dec 2007
Posts
77
Mentioned
0 Post(s)
Quoted
0 Post(s)
Nice tutorial! I actually learnt alot :P

By the way,

Code:
If(FindBitmapToleranceIn(copper, x, y, MIX1, MIY1, MIX2, MIY2, 35)) then
begin
Writeln('Found the copper bitmap') //(Shouldnt it be a semicolon there? :P )
Mouse(X, Y, 5, 5, true); // This thing doesn't seem to work ? ;o It does nothing :(
end else Writeln('Could not find bitmap'); //Says that we could not find it
FreeBitmap(copper); //This then frees the bitmap

25. Originally Posted by noobscam
Nice tutorial! I actually learnt alot :P
No worries, this tutorial was made for SCAR so I will update it for Simba (Even though most of the stuff is the same)

By the way,

Code:
If(FindBitmapToleranceIn(copper, x, y, MIX1, MIY1, MIX2, MIY2, 35)) then
begin
Writeln('Found the copper bitmap') //(Shouldnt it be a semicolon there? :P )
Mouse(X, Y, 5, 5, true); // This thing doesn't seem to work ? ;o It does nothing :(
end else Writeln('Could not find bitmap'); //Says that we could not find it
FreeBitmap(copper); //This then frees the bitmap
For the second line, no there doesn't need to be a semicolon there if it is just a If ... Then ... Else. If it was a If ... Then Begin ... End Else yes it would need a semicolon. The one that doesnt use begin and end will only support one line. Let me give an example.

Code:
If FindDeformedBitmapToleranceIn(YouSTA, STX, STY, 10, STY+1, 145, 400, 50, 0, False, A) Then
STY := STY + 1
Else
Harv := True;
That is some code from a script I am currently working on, as you can see it doesn't require a semicolon after the STY line. However if I were to do the begin and end it would need one, refer to the following code.

Code:
  If Not FindColorTolerance(X, Y, 16760704, 11, 32, 13, 49, 5) Then
Begin
Writeln('Blah');
TerminateScript;
End Else Writeln('Whatever');
Hope that clears things up. And for the Mouse line you have to make sure you use the SRL Include and call SetupSRL; first thing in your script, for example

Code:
Program new;
{.Include SRL/SRL.scar}
Begin
SetupSRL;
MMouse(50, 50, 4, 4);
End;
Edit:This tutorial has been remade with more pictures added and more bitmap functions and has been changed to work properly with Simba.
Last edited by cycrosism; 01-23-2011 at 01:16 PM.