Author Topic: Problem with file path  (Read 4646 times)

0 Members and 1 Guest are viewing this topic.

Offline vince

  • Newbie
  • Posts: 6
    • View Profile
Problem with file path
« 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.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem with file path
« Reply #1 on: August 06, 2021, 08:14:33 am »
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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem with file path
« Reply #2 on: August 06, 2021, 08:38:01 am »
I think your problem is because you are actually loading it correctly but handling the logic incorrectly. According to the Wiki for _LOADIMAGE:

Quote
Valid LONG handle returns are less than -1 (handle& < -1).

So you are getting a valid handle but telling yourself that it is invalid.
Shuwatch!

FellippeHeitor

  • Guest
Re: Problem with file path
« Reply #3 on: August 06, 2021, 09:24:01 am »
Yeah, that's correct. A handle = -1 or 0 indicates failure to load. Change it to this:

Code: QB64: [Select]
  1.  
  2. i = _LOADIMAGE("as.png")
  3. IF i >= -1 THEN PRINT "Error loading image..": END
  4. _PUTIMAGE (0, 0), i

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with file path
« Reply #4 on: August 06, 2021, 10:16:59 am »
Under Run menu "Output EXE to Source Folder" is bulleted?

No, I guess that gets a different error.
« Last Edit: August 06, 2021, 10:19:01 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with file path
« Reply #5 on: August 06, 2021, 10:27:57 am »
Try this:
Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2. i = _LoadImage("as.png")
  3. If i >= -1 Then Print "Error loading image..": End
  4. _PutImage (0, 0), i
  5.  
  6.  
  7.  

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem with file path
« Reply #6 on: August 06, 2021, 10:42:42 am »
@bplus
Try this:
Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2. i = _LoadImage("as.png")
  3. If i >= -1 Then Print "Error loading image..": End
  4. _PutImage (0, 0), i
  5.  

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:

Code: QB64: [Select]
  1.  
  2. i = _LOADIMAGE("as.png")
  3. IF i >= -1 THEN PRINT "Error loading image..": END
  4. _PUTIMAGE (0, 0), i
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with file path
« Reply #7 on: August 06, 2021, 10:44:23 am »
@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.
« Last Edit: August 06, 2021, 10:45:38 am by bplus »

FellippeHeitor

  • Guest
Re: Problem with file path
« Reply #8 on: August 06, 2021, 10:49:21 am »
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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with file path
« Reply #9 on: August 06, 2021, 11:00:14 am »
OP:
Quote
I have run the following bit of code and it keeps erroring when it gets to the _loadimage line.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem with file path
« Reply #10 on: August 06, 2021, 11:03:12 am »
The error he was getting was not a QB64 error.

Quote
I just keep getting the "Error loading image.." message

That error is one that he made himself.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with file path
« Reply #11 on: August 06, 2021, 11:03:43 am »
BTW this will error out on line 5, the graphics command if screen has not been set up for graphics:
Code: QB64: [Select]
  1.  
  2. i = _LoadImage("as.png", 32)
  3. If i >= -1 Then Print "Error loading image..": End
  4. _PutImage (0, 0), i
  5.  
« Last Edit: August 06, 2021, 11:08:03 am by bplus »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem with file path
« Reply #12 on: August 06, 2021, 11:05:01 am »
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.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with file path
« Reply #13 on: August 06, 2021, 11:11:28 am »
Yeah misdiagnosed problems are bane of my programming experience.

Offline vince

  • Newbie
  • Posts: 6
    • View Profile
Re: Problem with file path
« Reply #14 on: August 06, 2021, 11:21:43 am »
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.