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

This technical tip explains how .NET developers can Convert GIFF Image Frame to WebP Image inside their .NET applications. Aspose.Imaging enables you to extract a frame or frames from any existing GIFF image and convert it to WebP format. This article shows how you can extract a particular frame from a GIFF image and convert it to a WebP image. Here are some important steps for the conversion, Load an existing GIFF image into an instance of Image using the factory method Load, Create and initialize an instance of GifImage class, Create and initialize an instance of WebPImage class, Access the GIFF image Frame with GifImage.Blocks property, Create and initialize an instance of WebPFrameBlock class, Add WebP frame to WebP image block list, Set WebP image options and Save WebP image.
//your code here...// 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

Url: http://www.aspose.com/.net/imaging-component.aspx

Language: C# | User: Sheraz Khan | Created: Mar 24, 2016 | Tags: Read XMP Data from Images Write XMP Data to Images Extensible Metadata Platform embedding XMP information write XMP metadata to images Specify size of image .NET image processing