by
8,582 17

How to Convert GIFF Image Frame to WebP Image inside .NET Applications

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1129710/How-to-Convert-GIFF-Image-Frame-to-WebP-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet. // Converting GIFF Image Frame to WebP Image //[C# Code Sample] // Load GIFF image into the instance of image class. using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"D:\animation.gif")) { // Create an instance of GIFF image class. Aspose.Imaging.FileFormats.Gif.GifImage gif = image as Aspose.Imaging.FileFormats.Gif.GifImage; if (gif == null) return; // Load an existing WebP image into the instance of WebPImage class. using (Aspose.Imaging.FileFormats.Webp.WebPImage webp = new Aspose.Imaging.FileFormats.Webp.WebPImage(image.Width, image.Height, null)) { // Loop through the GIFF frames for (int i = 0; i < gif.Blocks.Length; i++) { // Convert GIFF block to GIFF Frame Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock gifBlock = gif.Blocks[i] as Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock; if (gifBlock == null) { continue; } // Create an instance of WebP Frame instance by passing GIFF frame to class constructor. Aspose.Imaging.FileFormats.Webp.WebPFrameBlock block = new Aspose.Imaging.FileFormats.Webp.WebPFrameBlock(gifBlock) { Top = (short)gifBlock.Top, Left = (short)gifBlock.Left, Duration = (short)gifBlock.ControlBlock.DelayTime }; // Add WebP frame to WebP image block list webp.AddBlock(block); } // Set Properties of WebP image. webp.Options.AnimBackgroundColor = 0xff; //black webp.Options.AnimLoopCount = 0; //infinity webp.Options.Quality = 50; webp.Options.Lossless = false; // Save WebP image. webp.Save(@"D:\saveAnimation.webp"); } } //[VB.NET Code Sample] ' Load GIFF image into the instance of image class. Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load("D:\animation.gif") ' Create an instance of GIFF image class. Dim gif As Aspose.Imaging.FileFormats.Gif.GifImage = TryCast(image, Aspose.Imaging.FileFormats.Gif.GifImage) If gif Is Nothing Then Return End If ' Load an existing WebP image into the instance of WebPImage class. Using webp As New Aspose.Imaging.FileFormats.Webp.WebPImage(image.Width, image.Height, Nothing) ' Loop through the GIFF frames For i As Integer = 0 To gif.Blocks.Length - 1 ' Convert GIFF block to GIFF Frame Dim gifBlock As Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock = TryCast(gif.Blocks(i), Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock) If gifBlock Is Nothing Then Continue For End If ' Create an instance of WebP Frame instance by passing GIFF frame to class constructor. Dim block As New Aspose.Imaging.FileFormats.Webp.WebPFrameBlock(gifBlock) With { _ Key .Top = CShort(gifBlock.Top), _ Key .Left = CShort(gifBlock.Left), _ Key .Duration = CShort(gifBlock.ControlBlock.DelayTime) _ } ' Add WebP frame to WebP image block list webp.AddBlock(block) Next ' Set Properties of WebP image. webp.Options.AnimBackgroundColor = &Hff 'black webp.Options.AnimLoopCount = 0 'infinity webp.Options.Quality = 50 webp.Options.Lossless = False ' Save WebP image. webp.Save("D:\saveAnimation.webp") End Using End Using
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus