QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: vince on August 06, 2021, 06:54:10 am
-
I am scratching my head with this very simple issue (possibly an issue on my part). I thought that when a file of any kind is referenced from your compiled program that it is relative to where your .EXE file is. I have run the following bit of code and it keeps erroring when it gets to the _loadimage line. The file is in the same directory as the .EXE and it is spelled correctly. I have even tried to use the full path to load the file, but that also fails.
DIM i AS LONG
i = _LOADIMAGE("as.png")
IF i < -1 THEN PRINT "Error loading image..": END
_PUTIMAGE (0, 0), i
I just keep getting the "Error loading image.." message
Call me stupid, I don't mind, as long as I can get past this.
-
Can you share the image file? Is it perhaps saved in a more modern version/format than our old code can recognize? I don’t *think* the png format has had any new revisions for a while, but I wouldn’t swear to anything.
-
I think your problem is because you are actually loading it correctly but handling the logic incorrectly. According to the Wiki for _LOADIMAGE:
Valid LONG handle returns are less than -1 (handle& < -1).
So you are getting a valid handle but telling yourself that it is invalid.
-
Yeah, that's correct. A handle = -1 or 0 indicates failure to load. Change it to this:
-
Under Run menu "Output EXE to Source Folder" is bulleted?
No, I guess that gets a different error.
-
Try this:
-
@bplus
Try this:
That looks suspiciously similar to Fellippe's answer, lol ;)
Yeah, that's correct. A handle = -1 or 0 indicates failure to load. Change it to this:
-
@bplus
That looks suspiciously similar to Fellippe's answer, lol ;)
Yeah but Fellippes errors out and mine doesn't because of the screen line.
The error was coming from line 3.
-
I never assumed this was the full code, but a snippet removed from another piece of code. My reply relies solely on the fact that he was checking for the handle incorrectly, as Zach had pointed out. Using _LOADIMAGE without passing the mode in the second parameter without being in graphical mode will indeed error.
-
OP:
I have run the following bit of code and it keeps erroring when it gets to the _loadimage line.
-
The error he was getting was not a QB64 error.
I just keep getting the "Error loading image.." message
That error is one that he made himself.
-
BTW this will error out on line 5, the graphics command if screen has not been set up for graphics:
-
I'm not doubting that it will create an error. But like he was originally saying, the error was "Error loading image..", which is an error that he wrote himself to display for invalid handles but he was checking the handle incorrectly.
-
Yeah misdiagnosed problems are bane of my programming experience.
-
I now know there was a logic error with the IF statement (my bad, thanks Spriggs).
Once I made that change I was still getting an error with the _putimage (Illegal function call). I changed the SCREEN statements mode to 32 (noticed bplus had that in the SCREEN statement) and it worked OK. So there were a couple of problems there.
Thanks for all your responses, appreciated.