microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.35k stars 678 forks source link

Implementing a control to display animated WebP files #7136

Closed dustincleveland closed 1 year ago

dustincleveland commented 2 years ago

I'd like to implement a control, a codec, or anything that will let me render animated WebP files within a C# Windows App SDK application. The solution needs to be performant; on par with the animated GIF rendering natively available via the Image control.

I've been scouring all the resources I can find for some kind of guidance on this. I've come across WIC, Win2D, the Windows.Graphics.Imaging namepsace, several outdated libraries (such as the Lumia Imaging SDK), and this blog post. I don't really have experience with Windows graphics systems, so all of the new knowledge is a little overwhelming, and I'm having a hard time trying to determine which avenue would be the most modern and best starting point. I'm honestly not even sure if this is the right place to ask, but I saw an issue that was closed about adding animated WebP support to the Image control that made me think it might be.

Would someone please help point me in the right direction on this, or offer any advice to help focus my effort? Thanks!

castorix commented 2 years ago

You can use the WebView2 control, which supports animated WebP files

dustincleveland commented 2 years ago

I can give that a shot, but I don't expect that a WebView2 will support virtualization? I'd like to support displaying a large number of files in a staggered layout.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Wufus commented 6 months ago

Animated WebP still not supported.

castorix commented 6 months ago

I just tested with WIC (IWICBitmapDecoder) and it works on my Windows 10 OS (22H2) although WebP is not in Native decoders

castorix commented 5 months ago

I uploaded a test : WinUI3_WIC_WebP for a control using a SwapChainPanel (Direct2D) and MMIO functions to read WebP attributes I tested with WebP files I found on Google or others I created from GIF/MPEG

kaismic commented 3 months ago

I have the same issue and it would be great if BitmapImage supports animated webp images, not only gif

kaismic commented 3 months ago

I have the same issue and it would be great if BitmapImage supports animated webp images, not only gif

Actually I just found about Magick.NET and used it to convert webp to gif in my application and it worked for me.

castorix commented 3 months ago

I have the same issue and it would be great if BitmapImage supports animated webp images, not only gif

Did you test the "WebPControl" control ?

kaismic commented 3 months ago

I have the same issue and it would be great if BitmapImage supports animated webp images, not only gif

Did you test the "WebPControl" control ?

I just tried it but the image in WebPControl doesn't seem to enlarge when I increase the height or width of the control. Is it possible to resize the image when the control's size changes?

castorix commented 3 months ago

I just tried it but the image in WebPControl doesn't seem to enlarge when I increase the height or width of the control. Is it possible to resize the image when the control's size changes?

Yes, I have voluntarily put it inside a ScrollViewer to get Scrollbars when the image is too big You can remove the ScrollViewer and for example use HorizontalAlignment="Stretch" VerticalAlignment="Stretch" for the control in XAML And I have fixed its size and centered it to avoid stretching, at lines :

   //this.Width = m_nCanvasWidth;
   //this.Height = m_nCanvasHeight;

and

 //destRect.left = (nWidth - nFrameWidth) / 2.0f;
 //destRect.top = (nHeight - nFrameHeight) / 2.0f;
 //destRect.right = destRect.left + (float)nFrameWidth;
 //destRect.bottom = destRect.top + (float)nFrameHeight;

then it will be stretched, but it is not great for the resolution :

image

kaismic commented 3 months ago

@castorix I really appreciate your help and your suggested change works without any problem. However, meanwhile, I also tried using WebView2 as you have mentioned before and I think that control is potentially more suitable for my project. So I will try using it first and see if it works out. Thanks for your help.