Cannot get to work

Trying to update to API2. I simply want to save a picture file to disk. This line worked on an older version.

p.Save(f, Picture.Formats.JPEG)

where p is a picture, f is a folderitem and jpeg is one of the FileTypes.

I get “UnsupportedOperationException”:
Saving a multi-representation Picture is not supported

In former times a picture was a picture. Now it can be different things. You have a picture with multiple representations. You need to get a simple picture out of your existing picture. See Picture.BestRepresentation - Xojo Documentation .

Load a simple picture (a gif from the web with a small width / height) and try to save it as is.

Compare the results / search why the one that refuse to be saved is different from the one you can save…

You may try to save that one as png…

Shut down everything, reboot, load only Xojo and try to save…

The picture is created from an ascii string in an sqlite database.
The following code creates the picture - which displays fine in a DesktopCanvas. The string is in “s”.

b=BinaryStream.Create(f, False)
If f <> Nil then
if f.Exists then
Return p
end if
end if

What may also work:

p = Picture.FromString(DecodeBase64(s))

I think this creates a „normal“ picture that could be saved as you expected.

Your title is false… misleading!

Is the above generated image loadable in… a Paint progral ? (Firefox, Paint, Preview, GIMP) ?

Did you checked if the Picture is valid in the debugger ?

The piece of code you quoted generates an image on disk loadable by any paint program. I have tested it.
My problem is not how to generate an image, but once I have an image, how to save it to disk, as the title of my first post says.

Here’s a fragment of my code to do that:

Var  atFile As FolderItem, binstr As BinaryStream, image as MemoryBlock

  binstr = BinaryStream.Create (atFile, False)
catch e as IOException
// log the error here
end Try

binstr.write (image)                                                           // Write image out
binstr.flush ()
binstr.close ()                                                                // Wrote the file out OK, can close it now

I’ve not had a problem with this.

After you have your Picture (p) created, have you checked p.ImageCount to verify that you are not ending up with a multirepresentation picture? Could be that a multi-res image made its way into the database.

1 Like

I’m sorry, there must be more going on here than I’m grasping… The first thing your code does is to write an image file on disk that is “loadable by any paint program”. Isn’t that exactly what you are trying to accomplish?

From where is the picture ? Does it have several resolution ?

Thank you all very much for your help.
The good news is that I updated my system to the latest version (Catalina 10.15.7), and now my code from the first post works fine. I cannot replicate the errors.

Maybe I should have tried Emile’s suggestion (reboot) first.