r/qb64 • u/TheOuterLinux • Aug 01 '19
I need help loading a file filled with comma seperated COLOR numbers to display an image
I have a GameOver image I created using a Python script I made to convert images pixel-by-pixel to QB's COLOR numbers. You can find the project here: https://theouterlinux.gitlab.io/website/Projects/Linux/img2qb/img2qb.html, and any questions or advise by more seasoned QB programmers would be welcomed. Anyway, I know how to embed the DATA part into the project itself, but I don't know how to load from a file. So far, I have tried:
SCREEN 13
OPEN "D:\GAMEOVER.QBD" FOR INPUT AS #1 'My img2qb.py script exports a plain text file as filename.qbd
DIM ARRAY(160, 100)
CLS
FOR Y = 1 TO 100
FOR X = 1 TO 160
INPUT #1, ARRAY(X, Y)
READ DotColor
PSET (X, Y), DotColor
NEXT X
NEXT Y
...but it throws errors and I have no idea how to fix it. I know about QB64's built in functions for loading images but if I want to make something that's backwards compatible with QB45, I can't use them. It would be nice if QB64 had an "Export as QB45 project" option. I also seem to not be able to go above 160x100 for DATA on QB45 or QBX, hence the GameOver image size.
1
u/Kobolticus Aug 02 '19
if the image information is stored in a DATA line then you need to use the meta command
'$INCLUDE: 'D:\GAMEOVER.QBD'
then READ ARRAY(X,Y) to load the image data
If you want to load it from a file directly with INPUT #1, then you need to save it as sequential values, with no DATA infront. You can still have it comma (,) delimited but you would have to account for that in your code as you read the information into the array.
The simplest thing would be have your python script store the color information in an array and write the array directly to the file then QB should be able to read the information back directly with a; GET #1,,ARRAY() You would have to open the file with; OPEN "D:\GAMEOVER.QBD" FOR BINARY AS #1
There are so many ways to achieve what your trying to do, and those are probably the simplest.
1
u/Kobolticus Aug 02 '19
based on the example QBD file in the download this code would load the image in both QB45 and QB64, probably not anything earlier but then I went straight from GWbasic to QB45 so I don't know for sure. though with this method you don't even need an array, but I'll comment in loading it to an array too.
'$INCLUDE: 'GAMEOVER.QBD' SCREEN 13 DIM ARRAY(160, 100)
CLS FOR Y = 1 TO 100 FOR X = 1 TO 160 '-----no need for an array version------ READ DotColor PSET (X, Y), DotColor '--------------------------------------- '---------Load to array version--------- ' READ ARRAY(X,Y) ' PSET (X, Y), ARRAY(X,Y) '--------------------------------------- NEXT X NEXT Y
I believe to get a whole 320x200 image in QB45(in an array) you have to set the arrays to DYNAMIC to access more memory, but its been years since I've played with QB45(and even then I always used DirectQB) so I can't remember just how to do that. it might be '$DYNAMIC but I'm not sure. However using DATA you don't need an array if you wanted, and therefore could just code all 320x200 into data to load directly with the 'no need for an array version'.