PDA

View Full Version : Loading bitmaps from the web!



The Element
08-10-2007, 08:25 PM
Sick of those LONG bitmap strings? Looking for something fresh? Then this is the thread for you!

This is my first tutorial so please tell me if I do anything wrong.

First off we need to get the bitmap string. Run a bitmap to string command. If the bitmap is very big then use the Mass Bitmap to String program included with scar.

Next take your code and remove all of the 's and +s and then one line it.

Bad code :


'aosdoinancnewlwmda'+
'ladmckslwmd'

Good code :

aosdoinancnewlwmdaladmckslwmd

Why do we do this?

Well, when you get the text from the web page it will return the text as a string. And, when a function returns a string it automatically adds the 's to the string. So when we get the text off the page it would look like:

''gdsfegdfsfcsadf'+
'dsasdcsdfewfw'';

So you will see that the 's and +s are actually included in the string. That would be bad.

Next we need to setup a web hosting account. I reccomend phpnet.us or freehostia.

Once you are registerd you should go to the control panel for your page and go to your file manager. Open notepad and copy your code in. Remember, if any of your code is pink in scar then this won't work. Save your file and upload it to your page.

Now, for scar to connect to your page.

We will use a function called GetPage;. This returns all the text on a page.

GetPage();

Now, the page must (or should) start with http://. Copy your web page that the text is being hosted on into the GetPage parameter. Make sure it is a string.

Example:

GetPage('http://mywebpage.phpnet.us/mypicture.txt');

Now we need to have a variable to hold the data that we get. I will use the variable MyPicture.

MyPicture := GetPage('http://mywebpage.phpnet.us/mypicture.txt');

Now we should test. Use a simple writeln(); to see if it returns a correct string.

Tester :

program TestBitmapTutorial;
var
MyPicture : String;
begin
MyPicture := GetPage('http://mywebpage.phpnet.us/mypicture.txt');
writeln(MyPicture);
end.

If it wrote out your bitmap correctly then you are able to move on to the next step. If not then please review and see what you did wrong.

Now, adding it to a form. I won't go into much detail for this because it is really simple.

Just add :

Image1 := TImage.Create(frmDesign);
Image1.Parent := frmDesign;
Image1.Left := 17;
Image1.Top := 4;
Image1.Width := 34;
Image1.Height := 30;
//Go To Have This After The Image!!!
//Loads Bitmap To String
target := MyPicture;
//Dont No What This Does :P , Canvas Gets The Picture?
C:= GetBitmapCanvas(target);
//34 and 30 are the size of the pic.
//Paints The Picture. Just Keep The Zeros The Same, And Change
//The 34 and 30 to the size of bitmaps (BitmapFromString(34<<, 30<<,stuff here)
CopyCanvas(C, Image1.Canvas, 0, 0, 34, 30, 0, 0, 34, 30);

To your InitForm procedure.

NOTE: There are comments for learning.

Pretty simple eh?

Please post.

The Element

EDIT: Pictures coming!

Sp0rky
08-10-2007, 08:33 PM
Do you mean GetPage, not GetUrl?

:p

The Element
08-10-2007, 08:35 PM
Darn -.-.

Edited :p...you always catch my mistakes

Spky
08-10-2007, 08:49 PM
I give up.

The Element
08-10-2007, 08:50 PM
I give up.

Sorry? Did you have any problems?

3Garrett3
08-10-2007, 08:50 PM
I give up.

What, you mean that this nub is better than you?

The Element
08-10-2007, 08:52 PM
Please don't call me a "nub" or a "noob" or a "leecher". I am trying to learn. Any of those terms refer to people who either offended someone else or does not give back or the community. I am trying to give back.

Spky
08-10-2007, 08:52 PM
Read http://www.villavu.com/forum/showthread.php?t=15063?t=16595

And yeh, your not a nub:p You just forgot some stuff.

The Element
08-10-2007, 09:03 PM
I'm sorry,

I looked at the thread and it didn't look like I missed anything othere then BitmapToString2. I will add it in. Please inform me of what I missed.