Saving a Multi-Representation Picture is Not Supported

If I try to save an animated gif from the clipboard to a file using Picture.SaveAsGif I get an UnsupportedOperationException error with the reason given that saving a multi-representation picture is not supported. If I try to write it to a file using a binary stream I get a TypeMismatchException error. Any idea how to save an animated gif from the clipboard?

You should share your code for this…

Well, if there is GIF data on the clipboard, you could maybe get it with RawData methods.
Or if it’s a file reference, ask for folder item.
Than write the data (as string) to binary stream.

You can’t simply ask for a picture as this may only give first frame. And you can’t write a picture directly to binary stream.

[quote=323608:@Christian Schmitz]Well, if there is GIF data on the clipboard, you could maybe get it with RawData methods.
Or if it’s a file reference, ask for folder item.
Than write the data (as string) to binary stream.

You can’t simply ask for a picture as this may only give first frame. And you can’t write a picture directly to binary stream.[/quote]
I’m still working on this. The problem is I’ll have to rewrite that part of my application to deal with animated gifs. They appear as a picture on the clipboard but can’t be saved as a picture, which makes things rather muddled. The head scratcher is that I only recently ran into this problem in an app that I first created several years ago. There was a time when the app could save an animated gif from the clipboard, or at least the first frame of it, but now I get an error message when I attempt it in OS X. The Windows version of the app still works the same as before.

If all you need is the first frame, it is easy :

dim c as new Clipboard if c.PictureAvailable then dim p as picture = c.picture p.Save(GetSaveFolderItem("special/any", "mypic.jpg"), Picture.SaveAsJPEG) end if

Gif is not supported, but Jpg is.

MBS Plugin could do it, also multi image TIFF files are no problem.

[quote=324746:@Michel Bujardet]If all you need is the first frame, it is easy :

dim c as new Clipboard if c.PictureAvailable then dim p as picture = c.picture p.Save(GetSaveFolderItem("special/any", "mypic.jpg"), Picture.SaveAsJPEG) end if

Gif is not supported, but Jpg is.[/quote]
GetSaveFolderItem can’t be used from within a thread and I still get an UnsupportedOperationException error trying to save the first frame as a jpeg. I also get that error when trying to save c.picture to a PictureColumn in SQLite.

Which of your plugins are good for clipboard/pasteboard operations?

And probably never will
It presents a dialog and thats NOT ok from a thread
Instead of presenting the dialog IN the thread present it before you start the thread & pass use the folderitem the person selects to the thread
ie/ instead of code that is

   start thread
    have thread present GetSaveFolderitemDialog

do this instead

    present GetSaveFolderItemdialog (which returns a folderitem)
    create thread & pass it the folder item from the previous step to use

[quote=324989:@Norman Palardy]And probably never will
It presents a dialog and thats NOT ok from a thread
Instead of presenting the dialog IN the thread present it before you start the thread & pass use the folderitem the person selects to the thread
ie/ instead of code that is

   start thread
    have thread present GetSaveFolderitemDialog

do this instead

present GetSaveFolderItemdialog (which returns a folderitem) create thread & pass it the folder item from the previous step to use [/quote]
I was actually commenting on a code snippet that was offered in this thread. I don’t need a folder item dialog in the app, I’m saving c.picture as a temporary folder item and using it to do a pixel comparison with images that are stored in a database file. I could save the first frame of an animated gif in previous versions of the IDE but when I went back to the app to work on an update I got the OperationNotSupported exception error. I’m not sure what changed or when.

[quote=323608:@Christian Schmitz]Well, if there is GIF data on the clipboard, you could maybe get it with RawData methods.
Or if it’s a file reference, ask for folder item.
Than write the data (as string) to binary stream.

You can’t simply ask for a picture as this may only give first frame. And you can’t write a picture directly to binary stream.[/quote]
I finally got this figured out. I can pull an image out using RawData as you suggested and use it the way I need to.

That snippet was not intended as a bullet proof immediate solution, but as an example.

I would have believed you were able to replace it by your own getfolderItem or other folderItem constructor. How could I guess you wanted to save from within a thread ? None of your posts before mentioned it.

FWIW and for others who may need it, this works perfectly and does not throw any exception from a Thread Run event handler :

Sub Run() Handles Run dim c as new Clipboard if c.PictureAvailable then dim p as picture = c.picture p.Save(SpecialFolder.documents.child("mypic.jpg"), Picture.SaveAsJPEG) end if End Sub

[quote=325013:@Michel Bujardet]That snippet was not intended as a bullet proof immediate solution, but as an example.

I would have believed you were able to replace it by your own getfolderItem or other folderItem constructor. How could I guess you wanted to save from within a thread ? None of your posts before mentioned it.

FWIW and for others who may need it, this works perfectly and does not throw any exception from a Thread Run event handler :

Sub Run() Handles Run dim c as new Clipboard if c.PictureAvailable then dim p as picture = c.picture p.Save(SpecialFolder.documents.child("mypic.jpg"), Picture.SaveAsJPEG) end if End Sub [/quote]
I tried that code but I still get an UnsupportedOperationException on an animated gif. The only way I can save it from the clipboard is to use p = Clipboard.RawData("public.jpeg") but that only gets the first frame. An animated gif can’t be saved as a picture from the clipboard nor stored in a SQLite database as a picture. It has to be converted to a binary string.

I don’t know. I tested again the snippet I posted under macOS Sierra with 2017R1, and it saves nicely a jpg of the first frame.

I confirm Xojo does not support SaveAsGif under macOS.

At any rate, if what you want to do is to save the entire collection of frames, you should go with MBS plugins.

[quote=325406:@Michel Bujardet]I don’t know. I tested again the snippet I posted under macOS Sierra with 2017R1, and it saves nicely a jpg of the first frame.

I confirm Xojo does not support SaveAsGif under macOS.

At any rate, if what you want to do is to save the entire collection of frames, you should go with MBS plugins.[/quote]
I downloaded the MBS plugins. I’m taking a look at them.