GUI displays a png but refuses to display a jpg ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

GUI displays a png but refuses to display a jpg ?

08 May 2021, 14:23

Hi everybody,
This one is driving me nuts.
I have two identical images in the same folder : image 1.jpg and Image 1.png (actually the .png is the .jpg with a .png extension for testing purposes)
I'm trying to display the jpg in a GUI :
Gui, %guiName%: Add, Picture, x0 y0, %ImgLoc%
Gui, %guiName%: Show, NA

If %ImgLoc% points to the png, the image shows. If it points to the jpg, nothing shows.
I have checked a dozen times. %ImgLoc% is good and points to the right image, including its extension.
Both pictures differ only by their extension. They are not corrupted.

How is that possible ?... :shock:
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

08 May 2021, 14:58

Just as another check to make sure there is no extra space or something in one of the files, add this line before the lines you showed:

Code: Select all

MsgBox, % FileExist(ImgLoc) ? "File found" : "Cannot locate file"
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

08 May 2021, 15:00

I agree, and if it does not work, you can post your script to get feedback about it.
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

08 May 2021, 15:05

I'm finding that the opposite is true. If I have a .png that I copy to a .jpg extension, then it won't display in my GUI with the .jpg extension, but not the other way around.

Perhaps when displaying a picture with a .jpg extension, AHK actually is expecting it to be a .jpg file, but when displaying an actual JPEG file regardless of extension, it displays it based on its header information regardless of whether its extension accurately reflects what type of file it is.

Having said that, I don't see any value in having misleading file extensions. In case it's not clear, changing the extension of the file does not change what type of file it actually is. You may be able to open it in a picture viewer, but that is because it is using the file header information to interpret its contents, not making assumptions based on its extension.
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

08 May 2021, 15:25

Jose Hidalgo wrote:
08 May 2021, 14:23
actually the .png is the .jpg with a .png extension for testing purposes
...
If %ImgLoc% points to the png, the image shows. If it points to the jpg, nothing shows.
I'm thinking that you must have reversed something in what you typed here and what you are seeing is more like what I saw. I find it highly unlikely that the image file that it can't display is the original one for which the format of the file matches its extension while the one it is able to display is the one where you artificially changed the extension.

Are you sure it wasn't originally a PNG file, and you copied it and renamed it to a .jpg? That would make much more sense as to why it's not displaying the file with a .jpg extension that's not really a JPEG file.
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

08 May 2021, 15:38

I agree, and easy to fix: just use an image editor to save the files with the proper extensions (i.e., matching their file types).
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 04:38

Thanks for your replies. I understand that you need these basic verifications to be done. So I can confirm this to 100% :
  • The image file is a true jpg, generated by myself with Photoshop
  • When I saw that AHK wouldn't display it no matter what I tried, only then I duplicated it and changed the extension of the copy to png. AHK displays the fake png, but it won't display the real jpg.
  • Since then I have also replaced the fake png with a real png, just so nobody complains about it.
  • Yes, the image is "found", whether it's jpg or png, but not displayed if it's a jpg.
... sorry to disappoint you guys, but the problem is elsewhere :lol:

The script I'm working on has lots of dependencies, so here's a zip with a stripped down version (which still has dependencies). You can run it, it's harmless.
#q for displaying the image with the DynamicImage function (you'll see the various MsgBoxes which prove that the image is found)
#c to quit

To switch from jpg to png, you can edit line 659 :
JpgLoc := A_ScriptDir "\" DeviceFolder "\" Dyn0 "\" Dyn1 "\" DynName " " Dyn3 ".jpg"
Keep the JpgLoc name, just change the .jpg part to .png.
If it's .png it works, if it's .jpg it doesn't.

Hopefully you will understand what's going on, because this is driving me crazy.
Please don't make changes to this version of the script, as I won't be reusing it. Thank you.
Attachments
TEST SCRIPT.zip
(458 KiB) Downloaded 48 times
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 05:06

@Jose Hidalgo

can you try creating just a basic gui and test if the image shows up?

can you upload just the problem image?
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 05:22

I agree totally. If you’re going to provide a stripped down script, why send something with a bunch of directories and files and a path definition that makes it difficult to find the actual file in question? Can you just provide a script that adds the image to a GUI and the file itself and nothing else? We don’t need to be wading through everything else, and I don’t want to run that complex of a script without checking it out thoroughly, which I shouldn’t have to do.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 08:08

Listen guys, don't feel forced to do anything. It's OK, I understand.
I have spent more than 30 minutes stripping down the script already, just for you. If you think that the script is still complicated, then you should see the unstripped script and the 15.000 files it relates to, compared to the about 15 files that I sent you.
It's difficult for me to strip it anymore, because a lot of functions are inter-dependent, and all functions have a variety of arguments and variables (as you can see for yourselves just by reading the script), which in turn depend on external files such as the .ini files or the contents of the Rsrc folder. I can't strip that away, or else I would have to change the script completely.

If you had just asked, I would have told you that the images are in the Devices folder. You cannot miss them since there are only two files in that folder. But checking them would be useless : they are correct. I may not be an AHK expert, but I'm still able to guarantee when a jpg file or a png file is correct. The two files are attached to this message, so suit yourselves. Ultimately you don't have to check any of the folder contents (but feel free to do so).

The script is harmless (I have commented one by one all the lines where there were write instructions, and you can ALSO check that by searching for "write"). You should just take my word for it because I have no reason for it to be otherwise.
But feel free not to launch it. Again, you're not forced to do anything.
Attachments
Nighthawk Wood 1.png
Nighthawk Wood 1.png (8.39 KiB) Viewed 1337 times
Nighthawk Wood 1.jpg
Nighthawk Wood 1.jpg (19.32 KiB) Viewed 1337 times
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 08:18

No problem here.

Code: Select all

image = %A_ScriptDir%\test.jpg
UrlDownloadToFile, https://www.autohotkey.com/boards/download/file.php?id=13224, %image%
Gui, Add, Picture,, %image%
Gui, Show,, Test
You can add a MsgBox that displays the following three values directly, just before you show the GUI.

imgguiName

WantedHeight

ImgLoc
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 08:28

If the problem is that AHK can't display the file, it's pointless to provide that whole script and all the associated files and folders (and to spend 30 minutes doing it) when all that is needed is to provide the image file and:

Code: Select all

Gui, Add, Picture,, Nighthawk Wood 1.jpg
Gui, Show

Jose Hidalgo wrote: If you had just asked, I would have told you that the images are in the Devices folder.
That's what we did.


Did you try the following?
AHKStudent wrote: can you try creating just a basic gui and test if the image shows up?
I did, using your image, and it showed up. What happens when you run the following script (located in the same directory as your main script)?

Code: Select all

Gui, Add, Picture,, Devices\AE-OE\Audioquest\Nighthawk Wood 1.jpg
Gui, Show
return

GuiClose:
ExitApp
It also displayed the .png file.
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 09:07

OK, I ran your script, and it does seem to be behaving differently inside your script for whatever reason. I tried a few different things and couldn't figure out why, but since the basic test script works, that shows that it's possible and it just needs to be determined what else is causing the problem.
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 09:34

This seems like it should be easy to debug. Is the "Gui, Show" line ever reached?
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

09 May 2021, 09:38

Yes, I see where it reaches it and did different things before it and to it to make sure it was executing and so forth (different Gui, Show lines are executed depending on the file extension), but it wouldn't show it. But there must be a way since the test script works. I just didn't find the problem in my time spent on it.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 10:07

Yes, this confirms what I was thinking/saying from the start :
1. I never implied that AHK was buggy. That would be very unlikely.
2. There was no need to create a 3-line code to display a jpg image with a GUI function. I can do that too, and of course it works on its own.
3. I know for a fact that the pictures are correct. I understand people asking about it at the beginning, but now we can rule that out.

That of course means that something within my script is buggy, and I can't figure out why.
Which is why I provided a stripped-down version of my script, and not a 3-line script that obviously works.

Now it may be one of these two things :
- Either there's a real bug in my script, something that would be entirely my fault,
- Or my script is inducing an unexpected AHK behaviour in that particular context. It's unlikely like I said, but I can't rule it out completely. Because being able to display a png but not a jpg with the exact same function is weird, to say the least.
Like I said, if you go to line 659 and you change .png to .jpg, it just doesn't work anymore ! :shock:

I have of course tracked the image location. If I put a MsgBox, %ImgLog% right before the Gui, %imgguiName%: Add, Picture instruction, the path displays perfectly, whether it's a jpg or a png. But the GUI instruction doesn't display the jpg ! That's what's crazy !! :crazy:
boiler wrote:
09 May 2021, 09:07
OK, I ran your script, and it does seem to be behaving differently inside your script for whatever reason. I tried a few different things and couldn't figure out why
Thank you :) The fact that an expert like you can't figure out what's wrong at first sight, comforts me into the fact that this is not an obvious bug and that it may be well beyond my knowledge.
If that comforts anybody, I have tried to debug it for a long time on my own before requesting help.
With that said, nobody here is expected to help in anything. Nobody is forced to. Thanks for trying at least.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 10:34

To be more specific, here's the remaining code in the DynamicImage function, I have stripped everything in between :

Code: Select all

    MsgBox, %ImgLoc%
    Gui, %imgguiName%: Add, Picture, x0 y0 h%WantedHeight% w-1, %ImgLoc%
    Gui, %imgguiName%: Show
%ImgLoc% always displays the right file location. But in the whole script context, the png shows and the jpg doesn't.
Last edited by Jose Hidalgo on 11 May 2021, 10:44, edited 2 times in total.
User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 10:35

Jose Hidalgo wrote: If that comforts anybody, I have tried to debug it for a long time on my own before requesting help.
With that said, nobody here is expected to help in anything. Nobody is forced to. Thanks for trying at least.
No problem. I tried for a while, but I wasn't able to identify the issue. However, if you take the time to systematically strip things out of your main script until it approaches the small test script that works, the image will eventually be displayed, which will isolate the cause of the problem.

Jose Hidalgo wrote: Yes, this confirms what I was thinking/saying from the start :
1. I never implied that AHK was buggy. That would be very unlikely.
2. There was no need to create a 3-line code to display a jpg image with a GUI function. I can do that too, and of course it works on its own.
3. I know for a fact that the pictures are correct. I understand people asking about it at the beginning, but now we can rule that out.

That of course means that something within my script is buggy, and I can't figure out why.
Which is why I provided a stripped-down version of my script, and not a 3-line script that obviously works.
Not that it's important at this point , but if you re-read your first post of the thread, you'll see that it was very much implying that a basic three-line script trying to show the jpg file wouldn't show it, which is what led us down the path of just wanting to test such a simple script displaying the file. I think you'll agree if you look at it again. There was no mention of some larger script, and only assigning values to guiName and ImgLoc would have made the couple lines you showed us a complete script.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 10:44

Yes, my first post was a clumsy attempt at explaining that I had already done some testing, narrowing down the displaying part to a short script like this :

Code: Select all

    MsgBox, %ImgLoc%
    Gui, %imgguiName%: Add, Picture, , %ImgLoc%
    Gui, %imgguiName%: Show
I just don't understand how such a simple code doesn't work in the context of my script, given that %ImgLoc% is displayed right before the GUI is displayed, and it's always correct.
How could that possibly happen ? My debugging knowledge only goes so far, and once I've stripped down the function as much as I could, I don't see what more I could do...
Are there other debugging tools that I wouldn't know about ? I'm really lost here.
Last edited by Jose Hidalgo on 11 May 2021, 11:19, edited 1 time in total.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 149 guests