Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Has anybody experience with MODBUS to read temp sensors? Rudy M 28 1,616 02-27-2026, 04:21 PM
Last Post: Rudy M
  about Hardware Images and _DisplayOrder,Help! qbfans 11 547 02-11-2026, 07:10 AM
Last Post: SMcNeill
  Nth problem with hardware images Ikerkaz 9 481 01-23-2026, 02:58 PM
Last Post: bplus
  Hardware images questions Dav 5 462 12-04-2025, 04:18 PM
Last Post: Pete
  Hardware images...Talk to me! Unseen Machine 5 732 09-22-2025, 11:12 PM
Last Post: TempodiBasic

Forum Jump:


Users browsing this thread: 1 Guest(s)