Post by alix on Apr 23, 2008 11:27:39 GMT -5
I'm trying to make a photo slider and I wonder if there is a way of speeding it up a bit.
In the program below, I start by displaying small icon-like versions of each image. While I do this, I also do a loadimage of each full sized image. I did this thinking that if I loaded all the image beforehand with the loadimage command, then, when it was time to give the drawimage command, things would happened faster...
This is not the case, images are not displayed any faster.
What does the loadimage command really do ? Are the images from server loaded into the client's memory ?
I know this is usually a problem, i.e. not specific to RB, with photo sliders, they tend to be slow...But then, wouldn't it be nice if one could find a way with RB ?
Anyway, you can see the photo-slider in action here :
cliftonsnooze.runbasicnet.com/
And here is the program, using Brent's code :
In the program below, I start by displaying small icon-like versions of each image. While I do this, I also do a loadimage of each full sized image. I did this thinking that if I loaded all the image beforehand with the loadimage command, then, when it was time to give the drawimage command, things would happened faster...
This is not the case, images are not displayed any faster.
What does the loadimage command really do ? Are the images from server loaded into the client's memory ?
I know this is usually a problem, i.e. not specific to RB, with photo sliders, they tend to be slow...But then, wouldn't it be nice if one could find a way with RB ?
Anyway, you can see the photo-slider in action here :
cliftonsnooze.runbasicnet.com/
And here is the program, using Brent's code :
'
'
' PHOTO-SLIDER
'
'
' Initialize variables
'
QuotomaticDir$ = "public\quotomatic\"
QuoteImgUrl$ = "../public/quotomatic/images2"
QuoteImgDir$="public\quotomatic\images2"
'
' Wait while loading images by displaying their icons
'
dividerimg$=QuotomaticDir$+"divider.jpg"
loadimage "divider", dividerimg$
graphic #whileuwait, 5,20
filepath$=QuoteImgDir$+"\*.gif"
files #g, filepath$
if #g HASANSWER() then
count = #g rowcount()
#whileuwait drawimage("divider",0,0)
render #whileuwait
for i = 1 to count
if #g hasanswer() then
if i=1 then
print "please wait while photos are loading ...."
print
end if
'
'retrieve info for next file
'
dummy$ = #g nextfile$()
img$=QuoteImgUrl$;"/";#g NAME$()
'display iconized image
html "<img src="""; img$; """ width=""20"" height=""20"">"
'display black divider in between each icon
#whileuwait drawimage("divider",0,0)
render #whileuwait
'
'load the image in memory
'
filename$=#g NAME$()
loadimg$= QuoteImgDir$+"\"+filename$
pic$="pic"+str$(i)
loadimage pic$, loadimg$
end if
next
else
emptymsg$="there are no files in "
Print emptymsg$
end if
print" "
print" "
'
' Start slider
'
' put background into place
graphic #bg, 300,225
#bg place(0,0)
'#bg box(300,300)
'
' slide images
' Code by brent D. Thorn
'
totalpages = count
page = 1
playing = 0
firstime=0
[show]
'
' don't clear page the first time
'
if firstime=0 then
firstime=1
else
firstime=2
end if
if firstime=2 then cls
pic$="pic"+str$(page)
#bg drawimage(pic$,0,0)
render #bg
print
if page > 1 then link #prev, "Previous", [prev]
print " ";
if not(playing) then
link #play, "Play", [play]
else
link #pause, "Pause", [pause]
end if
print " ";
if page < totalpages then link #next, "Next", [next]
if playing then
html "
<script type=""text/javascript"">
<!--
var a = null;
var as = document.getElementsByTagName('A');
for (var i = 0; i < as.length; i++)
{
if (as[i].firstChild.data == 'Next')
{
a = as[i];
break;
}
}
if (a) window.setTimeout('window.location = a.href', 5000);
//-->
</script>"
end if
wait
[prev]
page = page - 1
goto [show]
[next]
page = page + 1
goto [show]
[pause]
playing = 0
goto [show]
[play]
playing = 1
goto [show]
wait