#### Archived

This topic is now archived and is closed to further replies.

# Image List

## Recommended Posts

Daboy    139
Hey, since no one answers me im gonna ask if this is how...If i add 3 images into an imagelist is that how i flip through them?

##### Share on other sites
Xorcist    122
Huh? you''re gonna have to explain that one a little better...

##### Share on other sites
Daboy    139
I want to flip through 3 images....will an imagelist do that?

##### Share on other sites
Xorcist    122
Well the imagelist itself won''t do the flipping, but you can store three images in the imagelist and then setup a picturebox or other graphical component that you can use to display the image in the imagelist you want. Then all you need to do is display them in the sequence you want, to create a simple animation.

##### Share on other sites
Guest Anonymous Poster
Can u explain how i can get it to flip through it??? Thx

##### Share on other sites
Alimonster    185
You can use mod to cycle through a series of numbers (if that''s what you mean). This gives you the remainder of a division, so the values can only ever be in the range [0..number-1]. Much like this:

SomeIndex := (SomeIndex + 1) mod 3; // cycles 0,1,2 inclusive

You can add in code like this:

ImageList1.GetBitmap(SomeIndex, MyBitmap);
SomeIndex := (SomeIndex + 1) mod 3;
// etc. (draw MyBitmap, whatever)

The next time you do a GetBitmap, SomeIndex will be the next number in the sequence. If it''s two (i.e. the last one, zero based) then it will become 0 again. Therefore, you can cycle through the images.

You can optimise mod when it''s a power of two. Replace it with an "and" with the power minus one. So for example,

SomeIndex := (SomeIndex + 1) mod 4;
becomes...
SomeIndex := (SomeIndex + 1) and 3; // much faster!

Btw, here''s a really cool and unrelated link: Blah.

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Guest Anonymous Poster
For some reason thats throwing up alot of errors....and what do i put for the timer''s event handler???

##### Share on other sites
Guest Anonymous Poster
Crap wrong post.... Ok dude...where do i put this code in?? and what do i put for some Index??? Thx

##### Share on other sites
Alimonster    185
I''ve created a small web page giving example code (with a downloadable project for you). Hop over to:

Animation

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Guest Anonymous Poster
ok cool ...Thx man but one more thing now...how can i get that to work in a timage??? and how can i activate that on a button click? Thx ALOT!

##### Share on other sites
Alimonster    185
It''s _really_ simple. First, dump a TImage down on yer form. Next, change the line of code that says:

"Canvas.StretchDraw(ClientRect, Bmp);"
to
"Image1.Canvas.StretchDraw(Image1.ClientRect, Bmp);"

...and that''s it

If you want to do it in a button, just cut the three or so lines of code from the Timer1Timer procedure and put in a button''s whenclickedon. I.e. put a button onto your form, double click it, and add in this code to its empty procedure code:

procedure TForm1.Button1Click(Sender: TObject);begin//code goes here  SomeIndex := (SomeIndex + 1) mod ImageList1.Count;  DrawImage;end;

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Guest Anonymous Poster
lol ok one last one.... i have this game as i might have said...and i dont know if this stuff will work in it... But incase it doesnt. How can i make it so that if u click a button it flips a Timage through a few pics??? I tried putting 2 image1.picture.loadfromfile in a row but that just jumps to the last one...how can i make it go to both??? Thx in advance

##### Share on other sites
Alimonster    185
Right, this is the last help I'll give before snapping and killing someone. You don't want that, do you? So here's how to do it with TImages without any TBitmaps at all... listen carefully, because this is a life and death matter now .

If you do two LoadFromFiles one after another, the first will be immediately replaced with the next. If you plan on doing that, either put the loading into a TTimer to delay it, or make the user press a button (for example). Either way, delay the loading.

One way is to declare the filenames in an array, then cycle through them as before when the user presses a button, like this:

// in the form's or class's Private section
MyFiles: array[0..2] of String;
SomeIndex: Integer;
procedure GetNextImage;

// in the FormCreate, set the bitmap names as appropriate...
MyFiles[0] := 'Blah.bmp';
MyFiles[1] := 'Blah2.bmp';
MyFiles[2] := 'Boobies.bmp';
SomeIndex := 0;
GetNextImage; // loads the first pic

procedure TForm1.GetNextImage;
begin
SomeIndex := (SomeIndex + 1) mod 3; // or "mod High(MyFiles);"
end;

// in the button for cycling through pictures

procedure TForm1.Button1Click(Sender: TObject);
begin
GetNextImage;
end;

Aaargh, that must be all the possibilities covered by now. If you need to do this from an ImageList, then I've already given you the code in one of the posts before.

Alistair Keys

P.S. I'm only joking. I snapped a long time ago...

EDIT - sonofabitch. What's the proper tag for doing good code snippets in messages? Is it "code"?
EDIT 2 - removed the tag that screwed up the code snippet. Doh.

Edited by - Alimonster on November 16, 2001 7:51:47 PM

Edited by - Alimonster on November 16, 2001 7:54:43 PM

##### Share on other sites
Guest Anonymous Poster
Dude i hate to say this but its not running for me.... :-( lol dont yell.... Its giving me errors with the MyFiles and the [0]
Well... Pkz help if not dont worry bout it uve helped enough

##### Share on other sites
Guest Anonymous Poster
It might be becuz i didnt put that first part in about the form or clsses private section....wtf is that??

##### Share on other sites
Alimonster    185
It''s the bit near the top that says "{ Private declarations }". It looks like this:

type
TForm1 = class(TForm)
private
{ Private declarations }
// <---- insert private stuff here (i.e. array, etc)
// e.g. MyFiles: array[0..2] of String;
protected
// etc

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Guest Anonymous Poster
Ok that fixed the errors with the my files BUT ..Look at this //

in the FormCreate, set the bitmap names as appropriate...
MyFiles[0] := ''Blah.bmp'';
MyFiles[1] := ''Blah2.bmp'';
MyFiles[2] := ''Boobies.bmp'';
SomeIndex := 0;
GetNextImage; // loads the first pic

procedure TForm1.GetNextImage;
begin
SomeIndex := (SomeIndex + 1) mod 3; // or "mod High(MyFiles);"
end;

Its throwing me erroes at the procedure... does taht all go in the form create??? And on the Get Next Image is f-in up too...

lol sorry dude but can ya help?

##### Share on other sites
Alimonster    185
** Bashes head off wall while screaming, "THERE IS NO GOD!" **

Okay... I''ve created another project for you. The zip contains the previous and new projects. Get it here.

Anyone feel like taking over? I''m feeling slightly woozy...

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Guest Anonymous Poster
Ok that was uncalled for...ive been trying to get this for over 2 weeks lol if u give up ive got nothing... and that project isnt what ive been trying to do ....I need to make an animation... what u gave me would make it so people have to click the button over and over...I on the other hand need it to make it so if u click it , it will go throw the animation. Dont give up quite yet bud :-) Dude what if i sent u my project and pics and u can put the code into it... well thx again hope to talk to u again for the last time!

##### Share on other sites
Alimonster    185
Sorry, just needed some stress relief .

Anyway, I think I''ve got your drift now. Here''s some new code for you. I''ve modified the second project so now it does this:

1) Press the start button to begin the animation
2) Animation then keeps on going forever, until...
3) you press the stop button.

Get the code here (not yo momma jokes this time ).

The trick is easy: you have a timer that cycles through the images, using GetNextImage. It starts off disabled. When you want to start the animation, enable the timer. It then does its thing regularly (here, once a second). When you want the animation to finish, disable the timer.

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Guest Anonymous Poster
Lol ok dude thats perfect but now how can i get it so that it stops after 1 run??? and is there a way i can get it to take the images out of an image list?? Right now i think its taking it from teh file .. i think but i need it to take liek 6 form an image list and than stop... THANKS AGAIN

##### Share on other sites
MButchers    123
Alimonster,

you''ve the patience of an oyster!

##### Share on other sites
Alimonster    185
I''m charging by the hour, don''t worry .

Right, I can sort out this request. I''ll have an example project up in about 1-and-a-half to 2 hours from this post, when I get home. In the meantime:

1) You can use the old code from one of the (many) previous posts... I''m pretty sure they contain code that can help (for getting images from imagelists)
2) You can stop the animation when it ends by checking the index after you update the timer...

// in timer procedure bit
// ...get next pic
// ...if SomeIndex = a_magic_num then
// ... ... disable the timer

As I said, I''ll post another program in a short while.

Alistair Keys

P.S. My response time is getting pretty slow for the next few days. I''m snowed under with work at the mo.

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

##### Share on other sites
Alimonster    185
I''m back, and the new program is up. Get it here (it''s Anim2 that I changed).

This one has a couple of checkboxes. The first is "Stop on Finish" and the second is "Reset on finish". That one sets the image back to the first one when it finishes, if StopOnFinish is set.

Things to note in the code:

The two new variables, "StopOnFinish" and "ResetOnFinish"
The extra code in the timer code
** It gets the images from the ImageList now **

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne