Can images be read from a file into an array?
#6
(02-17-2023, 01:17 AM)TerryRitchie Wrote:
(02-17-2023, 12:34 AM)PhilOfPerth Wrote: I have a folder containing several images (.jpg) that I want to place in an array, then pick any (or all) from that array to display. I don't see any appropriate commands that allow this; are there any? (simplicity is important to me!)  Wink

I do this all the time in my games. I use an array of LONG INTEGERS to preload images then call upon each array index when I need the images.

DIM Image(10) AS LONG

Image(0) = _LOADIMAGE("image001.jpg", 32)
Image(1) = _LOADIMAGE("image002.jpg", 32)
Image(2) = _LOADIMAGE("image003.jpg", 32)
Image(3) = _LOADIMAGE("image004.jpg", 32)
Image(4) = _LOADIMAGE("image005.jpg", 32)
etc..
etc..

You can assign descriptive variable names if you like as well:

WaterFall& = Image(0)
Forest& = Image(1)
SunSet& = Image(2)
etc..

_PUTIMAGE (0, 0), SunSet&
or
_PUTIMAGE (0, 0), Image(2)


Don't forget to free the images before your program terminates:

FOR i = 0 TO 10
    _FREEIMAGE Image(i)
NEXT i

Look at the code for any of my games and you'll see I use this method quite extensively.

Thanks Terry.
This looks exactly like what I'm trying to do.
But when I used this to build a simple model to work on, by typing this:

Dim Image(10) As Long
Image(0) = _LoadImage("RecPics/cat.jpg", 32)
Image(1) = _LoadImage("RecPics/cat.jpg", 32)
Image(2) = _LoadImage("RecPics/cat.jpg", 32)
Image(3) = _LoadImage("RecPics/cat.jpg", 32)
Image(4) = _LoadImage("RecPics/cat.jpg", 32)
_PutImage (0, 0), Image(2)
Sleep
_FreeImage (Image(2))

I get an "Illegal function call" error on line 7 (the _PutImage line).
(I have the cat.jpg image in a folder called RecPicS)

I'll have a look at some of your progs to see if i can spot what I'm doing wrong.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply


Messages In This Thread
RE: Can images be read from a file into an array? - by PhilOfPerth - 02-17-2023, 01:53 AM



Users browsing this thread: 8 Guest(s)