how to show a series of pictures like a video stream?

Posted By: pjotr987

how to show a series of pictures like a video stream? - 01/28/13 00:15

Hi people,
I face a problem now, that i have a sries of pictures. That ones i want to show on the screen like a video.
Has anyone a good sugestion how to solve it?

Thanks in advance
Posted By: MasterQ32

Re: how to show a series of pictures like a video stream? - 01/28/13 00:23

just play it as a video with media_play
or use an array with all pictures as a BMAP and then loop through it with a loop and wait. every cycle put the bitmap on a panel
Posted By: pjotr987

Re: how to show a series of pictures like a video stream? - 01/28/13 00:50

Hi masterq32,
Can u explain exactly how the second method works. A piece of demonsrating code would be great.

In any case thanks again
Posted By: Uhrwerk

Re: how to show a series of pictures like a video stream? - 01/28/13 00:58

You can also put all the images in a row and use a panel with a window element in it. You can then change the picture displayed in the window by changing the x coordinate of the window.

http://www.conitec.net/beta/apanel-window.htm
Posted By: Error014

Re: how to show a series of pictures like a video stream? - 01/28/13 23:10

Originally Posted By: pjotr987
Hi masterq32,
Can u explain exactly how the second method works. A piece of demonsrating code would be great.

In any case thanks again


So, you'll need an array of bmaps, right. Let's say you have 64 bitmaps:

Code:
BMAP* myanimmaps[64];



Well, you'll have to load them all, right? Assuming you don't want to spend months typing, you should name them all with a simple namescheme, such as "myanim0.bmp", "myanim1.bmp", etc. so we only have to put the number in there.

Then, we can load them, like this (put this in a function, such as your main-function)

Code:
STRING* tmpstr=str_create("#32");
for(i=0; i < 64; i++) {
//stitch the filename together
str_cpy(tmpstr,"myanim");
str_cat(tmpstr,str_for_int(NULL,i));
str_cat(tmpstr,".bmp");
myanimmaps[i] = bmap_create(tmpstr);
}



Sweet, so now you've got it all in memory. All that's left to do is to play it back.
Assuming you're animation is to be played back with 24 frames per second, then that means we have to wait 1/24 of a second after each frame, right? 1/24 = 0.04.
So here we go:

Code:
void playanimation() {
char i; //you'll need something bigger than char if you have more than 255 frames
for(i=0; i < 64; i++) {
//Draw the bmap - for instance, via:
draw_quad(myanimmaps[i],nullvector,NULL,NULL,NULL,NULL,100,0);
wait(-0.04); //check wait in the manual to learn why I pass a negative value here
}
}



And that's about it!

You can also use a panel to display it, and set the Panel's bmap-pointer to the actual frame (myanimmaps[i]), if you can't use draw_quad for some reason.


A last word on this - be aware that this way, all your frames are uncompressed in memory at all times. This might lead to an enormous increase in memory consumption. If it is an option, consider using the media_-instruction (and make your animation an actual movie), which streams the video, possibly improving that situation.
Of course, if its a short animation with few frames, you can do it this way.
Consider at least purging the bmaps if you don't need them, though (see bmap_purge in the manual to learn how to do this)
© 2024 lite-C Forums