Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Save_bitmap loop

This thread is locked; no one can reply to it. rss feed Print
Save_bitmap loop
Eradicor
Member #2,992
December 2002
avatar

Ok. Dont ask why i need following, program code. Just suffice to say, i need it:

I need something like this ->

while(x = 1000) {
draw_certain_bitmap_full_of_stuff();
save_bitmap(certain_bitmap,"certain(int x).bmp");
}

Now it should do 1000 bmp files containing certain_bitmap and the file names should be:

certain1.bmp
certain2.bmp
certain3.bmp
certain4.bmp
etc
...

And for curious, no this is not for making screen capturing, but is ment for very special kind of animation program for our next film project. :D

FAST ANSWERS PLEASE.. And correct too!

| Visit The site |
{Creating realms from dreams since 1995}

Mokkan
Member #4,355
February 2004
avatar

Like this?

int x = 1;
while(x <= 1000){
    char filename[64];
    sprintf(filename, "certain%d.bmp", x);
    draw_certain_bitmap_full_of_stuff();
    save_bitmap(certain_bitmap, filename);
    x++;
}

EDIT: Fixed code.

Onewing
Member #6,152
August 2005
avatar

Quote:

FAST ANSWERS PLEASE.. And correct too!

Sure! As soon as I find the question...

------------
Solo-Games.org | My Tech Blog: The Digital Helm

CGamesPlay
Member #2,559
July 2002
avatar

Don't forget to increment x :)

[append]
IRC beats CGamesPlay to the edit.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Jonatan Hedborg
Member #4,886
July 2004
avatar

First i considered not answering, because of your well, arrogant, tone.

But what the hey, i feel like "giving".

And you obviously dont have any idea what you are doing.

for(int i=1; i<=1000; i++)
{
  draw_certain_bitmap_full_of_stuff(certain_bitmap);
  char tmp[256];
  sprintf(tmp,"certain%i.bmp",i);
  save_bitmap(certain_bitmap,tmp);
}

Untested, naturally, so i can't give any guarantees, but that should do it.

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

ReyBrujo
Moderator
January 2001
avatar

I would use %04d instead, to get 0001, 0002, 0003, etc. But it is just my taste.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

A J
Member #3,025
December 2002
avatar

i would be more concerned with people still using sprintf hasn't the last 3 years of "secure" programming hyperbole from just about everyone meant anything?

and whats with using file[64] and file[256] ? how about using MAX_PATH

and what about clearing it before using it ?

___________________________
The more you talk, the more AJ is right. - ML

Jonatan Hedborg
Member #4,886
July 2004
avatar

I heard it mentioned that sprintf is "bad" in some way. Please elaborate =)
You don't need to clear it afaik, as it overwrites anything in the buffer and terminates with a \0. And i agree that %04i or even %05i would be better than just plain %i.

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

Evert
Member #794
November 2000
avatar

Quote:

I heard it mentioned that sprintf is "bad" in some way. Please elaborate =)

Buffer overruns. It doesn't check if it writes outside the size of the allocated memory buffer (because you don't tell it the size of the memory buffer).

Quote:

You don't need to clear it afaik

Correct.

Jonatan Hedborg
Member #4,886
July 2004
avatar

Right. That would be bad. But it's not an issue here anyway.

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

A J
Member #3,025
December 2002
avatar

Bad code is always an issue.
This is computer science not poetry.
Computer science i tell you computer science.. mwahwhaaa!!

___________________________
The more you talk, the more AJ is right. - ML

Eradicor
Member #2,992
December 2002
avatar

Jonatan Hedborg said:

First i considered not answering, because of your well, arrogant, tone.

Heh thats new.

Well when you are on a hurry you dont have luxuary of being polite.

Anyway i solved this problem another way. Thanks however. That filename routine comes handy else where tho.

| Visit The site |
{Creating realms from dreams since 1995}

Go to: