Picture.SaveAsPNG UnsupportedFormatException on Windows 10 with GDI+ enabled

I’m getting an UnsupportedFormatException when running this method in a Windows 10 PC with GDI+ enabled. I’ve tried running it on a different PC, also with Windows 10 but It runs ok and I don’t get the exception. I thought maybe GDI+ was missing in my first PC, but after looking it up online, it is supposed to be installed by default on Windows 10, so I cannot understand why I’m receiving the exception in the first place.

Maybe some of you guys can help me? Thanks!

Dim file As FolderItem = SpecialFolder.ApplicationData.Child(“PASSFORT”).Child(temp.png)

If (file = Nil) Then
// The file could not be created
Return -1

If (pic = Nil) Then
// The PFImage could not be converted
Return -2

pic.Save(file, Picture.SaveAsPNG)
pic = Picture.Open(file)

If (pic = Nil) Then
  // The picture file was not saved
  Return -3       
End If

End If
End If[/code]

Have you tried using isExportFormatSupported to see which formats are supported on that machine ? Normally, Windows should always support BMP.

or try a PNG Plugin like the one from us (MBS).
Which brings it’s own PNG library and doesn’t really on anything being installed.

What does the Message property of the exception say?

Uh, maybe it’s just a typo but shouldn’t there be quotes around temp.png in your Dim statement? Or is temp.png a variable?

there should be quotes. Often people just type something without letting compiled check it.

Thanks, I just forgot to add them when I pasted the original code and replaced the file name. As I already explained in my original post, there’s no compilation error. It runs OK on a Windows 10 PC and it doesn’t on another machine also with Windows 10.

@Greg O’Lone the message says: “SaveAsPicture doesn’t support format 150 in Windows.”

@Michel Bujardet - I need to use PNG because of the transparency, it is supposed to be supported by Xojo if GDI+ is enabled, which it is.

Maybe Xojo is not at fault, but that particular PC…

@Michel Bujardet Let’s assume that PC is at fault. Any Idea about how to get it fixed? I’m afraid this could also happen to some of our customers in the future…

Does that machine have Windows Media Player installed?

@Greg O’Lone Yes, on both of them.

Could it be a folder permissions issue? Look at the following post … http://forums.realsoftware.com/viewtopic.php?f=1&t=31784

The quick test for that is to switch the code to save as BMP which is definitely supported, GDI or not
If that fails too, Langue is onto something

My point was not to give up, but to diagnose which formats appear supported or not for debugging purposes. Since Xojo does nothing but request the system to save and load the picture, chances are that particular PC is at fault. If you get no picture supported, then you can bet the Windows version is corrupted.

In order to work around this bug, which once again maybe limited to that particular system, I see no other options than to use a library like MBS, or save in another format that support transparency, such as Gif, and then convert with some external tool.

I strongly believe this maybe a local artefact, and spending time working around that sole machine system corruption may very well be futile out there in the real world.

Do you try to use a bmp file (since this may be the default image file format…) ?