Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with a animated webp #27

Open
Lacro59 opened this issue Feb 10, 2021 · 14 comments
Open

error with a animated webp #27

Lacro59 opened this issue Feb 10, 2021 · 14 comments

Comments

@Lacro59
Copy link

Lacro59 commented Feb 10, 2021

When I try to load an animated webp, I get an error.
Will there be management of animated files?

@Beelink
Copy link

Beelink commented Mar 17, 2021

Yeah, it would be nice to see the support of animated files.

@MaxDeBy
Copy link

MaxDeBy commented Mar 19, 2021

Ditto. Could really use it.

@JosePineiro
Copy link
Owner

Please, give me more details.
Load animated WebP into ¿....?
Convert animated WebP to ¿...?

@Lacro59
Copy link
Author

Lacro59 commented Sep 20, 2021

With the version defined here, I've this error:
image
With any WebP animated image.

Actually, with the last commited version, there is no error but there is no image displayed.
Neverless, I can get file information:
image

@JosePineiro
Copy link
Owner

In the new version, the DLL suport animated WebP.
But it is trying to decode and render in an image (a windows bitmap).
Bitmaps are static, so they will hardly be able to present a moving image. In addition, the windows form control does not support animations either.

So the question is, what do you want that webP to become? Where do you want to present it? What container do you want to send it to?

@Lacro59
Copy link
Author

Lacro59 commented Sep 22, 2021

It does not need to handle the animation.
Ideally, we should be able to get every frame.
By their index for example.

@davidei1955
Copy link

davidei1955 commented Oct 18, 2021

As Lacro59 said, just be able to get every frame in a manner similar to the way an animated GIF is converted to an Image. In other words, I'd like an Image/Bmp that can be played using the System.Drawing.ImageAnimator.Animate(Image, EventHandler) Method.

See the example in https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imageanimator.animate?view=windowsdesktop-5.0

I found an example showing how to create a multi-frame Bitmap here: https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-creating-and-saving-a-multiple-frame-image-use . Rather than saving to a file, you'd probably want to save to a .MemoryStream

@holm76
Copy link

holm76 commented Feb 1, 2022

I need this too. Actually I would love to be able to throw a WEBP file into this library and be returned an object with a list of images. If the webp file is not an animation then there will only be 1 image in the images collection. There could also be like an IsAnimated property.
Im sure there are a bunch of other information about the file that can be returned as well. Like if animated then some info on framerate or something like that.

This would be awesome to have for sure.

@zhc341272
Copy link

zhc341272 commented Feb 1, 2022 via email

@davidei1955
Copy link

FWIW, I ended up using Magick.NET to convert WebP images to PNG's (single frame) or GIF's (animated). My code looks like:

    public static Bitmap NewBitmap(this FileInfo fi) {
        Bitmap bitmap = null;
        try {
            bitmap = new Bitmap(fi.FullName);
        } catch (Exception) {
          // use 'MagickImage()' if you want just the 1st frame of an animated image. 
          // 'MagickImageCollection()' returns all frames
            using (var magickImages = new MagickImageCollection(fi)) {
                var ms = new MemoryStream();                    
                if (magickImages.Count > 1) {
                    magickImages.Write(ms, MagickFormat.Gif);
                } else {
                    magickImages.Write(ms, MagickFormat.Png);
                }
                bitmap?.Dispose();
                bitmap = new Bitmap(ms);
                // keep MemoryStream from being garbage collected while Bitmap is in use
                 bitmap.Tag = ms;
            }
        }
        return bitmap;
    }

@holm76
Copy link

holm76 commented Feb 3, 2022

FWIW, I ended up using Magick.NET to convert WebP images to PNG's (single frame) or GIF's (animated). My code looks like:

    public static Bitmap NewBitmap(this FileInfo fi) {
        Bitmap bitmap = null;
        try {
            bitmap = new Bitmap(fi.FullName);
        } catch (Exception) {
          // use 'MagickImage()' if you want just the 1st frame of an animated image. 
          // 'MagickImageCollection()' returns all frames
            using (var magickImages = new MagickImageCollection(fi)) {
                var ms = new MemoryStream();                    
                if (magickImages.Count > 1) {
                    magickImages.Write(ms, MagickFormat.Gif);
                } else {
                    magickImages.Write(ms, MagickFormat.Png);
                }
                bitmap?.Dispose();
                bitmap = new Bitmap(ms);
                // keep MemoryStream from being garbage collected while Bitmap is in use
                 bitmap.Tag = ms;
            }
        }
        return bitmap;
    }

This works. But it takes a while to load the webp files. My browser can quickly load the same files. Maybe chrome is just optimized for webp files. Also they play at different framerates too.

Thanks for posting.

@priprii
Copy link

priprii commented Jun 17, 2022

Still no support for animated webp?

There doesn't seem to be any wrapper that handles them yet this one suggests being "the most complete wrapper", unfortunate.

Even Google's own decoding app doesn't support animated webp lol

@zhc341272
Copy link

zhc341272 commented Jun 17, 2022 via email

@davidei1955
Copy link

davidei1955 commented Jun 17, 2022

I've been using Magick.NET to convert WebP images animated GIFs for about 6 months - see my code example above. It's not super fast, but works well.
Also, the framerate issue that holm76 mentioned may have been fixed in the latest release of Magick.NET, see dlemstra/Magick.NET#1102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants