Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can images be read from a file into an array?
#4
(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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
RE: Can images be read from a file into an array? - by TerryRitchie - 02-17-2023, 01:17 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)