I need to play a GIF animation with transparency to play over a Canvas.
So basically I need the HTMLViewer to have a transparent background. This way I can put it on top of a canvas.
Is this possible?
I need to play a GIF animation with transparency to play over a Canvas.
So basically I need the HTMLViewer to have a transparent background. This way I can put it on top of a canvas.
Is this possible?
Maybe with plugins (MBS) or declares. I dont thing the htmlviewer can be transparent otherwise. But ive seen it been done before.
Only HTMLViewer supports animated gifs.
It may be possible with declares to set the HTMLViewer background content to transparent, and remove the border. I am pretty sure about the border, setting the background color may simply not be possible.
There is another way, though. If the canvas is transparent, place it over the HTMLViewer.
I suspect you could do it yourself; there’s probably a way to open a GIF file (The usual suspects are NSImage or CGImageSource) and get all the frames, then all you need is to read the GIF meta data (again with either NSImage or CGImageSource) and figure out the parameters.
Yup, CGImageProperties will allow you to read that meta data.
https://developer.apple.com/documentation/imageio/cgimageproperties/gif_dictionary_keys?language=objc
Thank you for the input;
I understand I can do the animation in a Canvas too. But the main issue is that the animation can play chunky when other things are doing heavy calculations in the main thread. An animated GIF inside a HTMLViewer always seems to play smoothly, even when the main thread is busy doing other stuff. HTMLViewer probably runs in the separate thread.
I also tried to use AVFoundation playing a movie, but it doesn’t play smoothly either when the main thread is doing something else.
Basically what I need is a simple loop animation that always plays smoothly.
So you are looking for a Mac only solution?
In that case, NSImageView would be my personal choice. It can play animated images smoothly, and you could use Xojos ImageWell, get rid of the frame via declare and add a handful of other declares to load the animated Gif as an NSImage.
Thanks Ulrich. Yes Mac only.
Will look at this asap.
(set)Framestyle, Animates and
Image are the declares for the image well, and something like initByReferencingFile is ok to turn an animated Gif into an NSImage.
But, sadly, while the animation plays even if you use a menu item or move the window, a tight loop on the main thread stops it
EDIT: A workable approach seems to be the use of CoreAnimation.
You can use MBS Plugins.
We have class to load and play GIF files.
And also an NSImageViewMBS class.
Then the main issue is that you need to free up your main thread.
GIF classes are listed here:
http://monkeybreadsoftware.net/pluginpart-gif.shtml
and example to play animated images is here:
http://monkeybreadsoftware.net/example-images-gif-animatedgif.shtml
A soulution that may help with HTML-Viewer with different background-colors is here
https://forum.xojo.com/7195-htmlviewer-border/0
you can define the background of the html-viewer by css.
Colors are not 100% the same as in xojo and transparency is possible but works not really well.
If that is not enough: maybe mbs.