working on it ...

Filters

Explore Public Snippets

Sort by

Found 6 snippets matching: ".net image processing"

    public by sherazam  4262  3  5  0

    How to Crop EMF Image using Shifts or Rectangle Approaches in .NET Applications

    This technical tip explains how .NET developers can Crop an EMF Image inside their .NET applications. Image cropping usually refers to the removal of the outer parts of an image to help improve the framing. Cropping may also be used to cut out some portion of an image to increase the focus on a particular area. Aspose.Imaging for .Net API supports
    // Enter here the actual content of the snippet.            // Cropping by Shifts
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfBezier.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
      using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
      {
        //Based on the shift values, apply the cropping on image
        //Crop method will shift the image bounds toward the center of image
        image.Crop(30, 40, 50, 60);
    
        // Set height and width
        pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
        pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
        //Save the results to disk
        image.Save(outputStream, pdfOptions);
      }
    }
     
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfBezier.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Based on the shift values, apply the cropping on image
    		'Crop method will shift the image bounds toward the center of image
    		image.Crop(30, 40, 50, 60)
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    // Cropping by Rectangle
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfExtPen.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
        using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
        {
            //Create an instance of Rectangle class with desired size
            //Perform the crop operation on object of Rectangle class
            image.Crop(new Aspose.Imaging.Rectangle(30, 50, 100, 150));
    
            // Set height and width
            pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
            pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
            //Save the results to disk
            image.Save(outputStream, pdfOptions);
        }
    }
    
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfExtPen.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Create an instance of Rectangle class with desired size
    		'Perform the crop operation on object of Rectangle class
    		image.Crop(New Aspose.Imaging.Rectangle(30, 50, 100, 150))
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    

    public by sherazam  4172  1  6  0

    How to Combine Two or Multiple Images into a Single Image inside .NET Apps

    This technical tip explains how .NET developers can combine single or multiple images inside their .NET applications. This example uses Graphics class and shows how to combine two or more images into a single complete image. To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface us
    // Enter here the actual content of the snippet.            
    // Combining Images using Graphics Class
    
    //[C# Code Sample]
    
    //Create an instance of JpegOptions and set its various properties
    Aspose.Imaging.ImageOptions.JpegOptions ImageOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
    
    //Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"two_images_result.jpeg", false);
    
    //Create an instance of Image and define canvas size
    using (var image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600))
    {
          //Create and initialize an instance of Graphics
          var graphics = new Aspose.Imaging.Graphics(image);
    
          //Clear the image surface with white color
          graphics.Clear(Aspose.Imaging.Color.White);
    
          // Draw Image
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input1.jpg"), 0, 0, 600, 300);
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input2.jpg"), 0, 300, 600, 300);
                    
          // Call save method to save the resultant image.
          image.Save();
    }
     
    //[VB.NET Code Sample]
    
    'Create an instance of JpegOptions and set its various properties
    Dim ImageOptions As New Aspose.Imaging.ImageOptions.JpegOptions()
    
    'Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = New Aspose.Imaging.Sources.FileCreateSource("two_images_result.jpeg", False)
    
    'Create an instance of Image and define canvas size
    Using image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600)
    	'Create and initialize an instance of Graphics
    	Dim graphics = New Aspose.Imaging.Graphics(image)
    
    	'Clear the image surface with white color
    	graphics.Clear(Aspose.Imaging.Color.White)
    
    	' Draw Image
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input1.jpg"), 0, 0, 600, 300)
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input2.jpg"), 0, 300, 600, 300)
    
    	' Call save method to save the resultant image.
    	image.Save()
    End Using
    
    

    public by sherazam  2996  0  6  1

    How to Create Thumbnails from PSD Files inside .NET Applications

    // Enter here the actual content of the snippet.         
    // Creating Thumbnails from PSD Files
    
    //[C# Code Sample]
    
    //Load a PSD in an instance of PsdImage
    using (Aspose.Imaging.FileFormats.Psd.PsdImage image = (Aspose.Imaging.FileFormats.Psd.PsdImage)Aspose.Imaging.Image.Load(sourceFilePath))
    {
        //Iterate over the PSD resources
        foreach (var resource in image.ImageResources)
        {
            //Check if the resource is of thumbnail type
            if (resource is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)
            {
                //Retrieve the ThumbnailResource
                var thumbnail = (Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)resource;
                //Check the format of the ThumbnailResource
                if (thumbnail.Format == Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB)
                {
                    //Create a new BmpImage by specifying the width and heigh
                    Aspose.Imaging.FileFormats.Bmp.BmpImage thumnailImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height);
                    //Store the pixels of thumbnail on to the newly created BmpImage
                    thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData);
                    //Save thumbnail on disc
                    thumnailImage.Save("D:\\test.bmp");
                }
            }
        }
    }
     
    //[VB.NET Code Sample]
    
    'Load a PSD in an instance of PsdImage
    Using image As Aspose.Imaging.FileFormats.Psd.PsdImage = CType(Aspose.Imaging.Image.Load(sourceFilePath), Aspose.Imaging.FileFormats.Psd.PsdImage)
    	'Iterate over the PSD resources
    	For Each resource In image.ImageResources
    		'Check if the resource is of thumbnail type
    		If TypeOf resource Is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource Then
    			'Retrieve the ThumbnailResource
    			Dim thumbnail = CType(resource, Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)
    			'Check the format of the ThumbnailResource
    			If thumbnail.Format = Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB Then
    				'Create a new BmpImage by specifying the width and heigh
    				Dim thumnailImage As New Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height)
    				'Store the pixels of thumbnail on to the newly created BmpImage
    				thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData)
    				'Save thumbnail on disc
    				thumnailImage.Save("D:\test.bmp")
    			End If
    		End If
    	Next resource
    End Using
    
    

    public by sherazam  2701  0  6  1

    How to Read and Write XMP Data to Images inside .NET Apps

    // Enter here the actual content of the snippet.//Create XMP Metadata, Write It And Read From File
    
    //[C# Code Sample]
    
    // Specify the size of image by defining a Rectangle 
    Aspose.Imaging.Rectangle rect = new Aspose.Imaging.Rectangle(0, 0, 100, 200);
    
    TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRGB);
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack;
    tiffOptions.BitsPerSample = new ushort[] { 8 };
    
    // create the brand new image just for sample purposes
    using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height)))
    {
          // create an instance of XMP-Header
          Aspose.Imaging.Xmp.XmpHeaderPi xmpHeader = new Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString());
    
          // create an instance of Xmp-TrailerPi 
          Aspose.Imaging.Xmp.XmpTrailerPi xmpTrailer = new Aspose.Imaging.Xmp.XmpTrailerPi(true);
    
          // create an instance of XMPmeta class to set different attributes
          Aspose.Imaging.Xmp.XmpMeta xmpMeta = new Aspose.Imaging.Xmp.XmpMeta();
          xmpMeta.AddAttribute("Author", "Mr Smith");
          xmpMeta.AddAttribute("Description", "The fake metadata value");
    
          // create an instance of XmpPacketWrapper that contains all metadata
          Aspose.Imaging.Xmp.XmpPacketWrapper xmpData = new Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
    
          // create an instacne of Photoshop package and set photoshop attributes
          Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage photoshopPackage = new Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage();
          photoshopPackage.SetCity("London");
          photoshopPackage.SetCountry("England");
          photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb);
          photoshopPackage.SetCreatedDate(DateTime.UtcNow);
    
          // add photoshop package into XMP metadata
          xmpData.AddPackage(photoshopPackage);
    
          // create an instacne of DublinCore package and set dublinCore attributes
          Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage dublinCorePackage = new Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage();
          dublinCorePackage.SetAuthor("Charles Bukowski");
          dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts");
          dublinCorePackage.AddValue("dc:movie", "Barfly");
    
          // add dublinCore Package into XMP metadata
          xmpData.AddPackage(dublinCorePackage);
    
          using (var ms = new MemoryStream())
          {
                        // update XMP metadata into image
                        image.XmpData = xmpData;
    
                        // Save image on the disk or in memory stream
                        image.Save(ms);
    
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
    
                        // Load the image from moemory stream or from disk to read/get the metadata
                        using (var img = (TiffImage)Aspose.Imaging.Image.Load(ms))
                        {
                            // getting the XMP metadata
                            Aspose.Imaging.Xmp.XmpPacketWrapper imgXmpData = img.XmpData;
                            foreach (Aspose.Imaging.Xmp.XmpPackage package in imgXmpData.Packages)
                            {
                                // use package data ...
                            }
                        }
         }
    }
     
    //[VB.NET Code Sample]
    
    ' Specify the size of image by defining a Rectangle 
    Dim rect As New Aspose.Imaging.Rectangle(0, 0, 100, 200)
    
    Dim tiffOptions As New TiffOptions(TiffExpectedFormat.TiffJpegRGB)
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack
    tiffOptions.BitsPerSample = New UShort() {8}
    
    ' create the brand new image just for sample purposes
    Using image = New TiffImage(New TiffFrame(tiffOptions, rect.Width, rect.Height))
    	' create an instance of XMP-Header
    	Dim xmpHeader As New Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString())
    
    	' create an instance of Xmp-TrailerPi 
    	Dim xmpTrailer As New Aspose.Imaging.Xmp.XmpTrailerPi(True)
    
    	' create an instance of XMPmeta class to set different attributes
    	Dim xmpMeta As New Aspose.Imaging.Xmp.XmpMeta()
    	xmpMeta.AddAttribute("Author", "Mr Smith")
    	xmpMeta.AddAttribute("Description", "The fake metadata value")
    
    	' create an instance of XmpPacketWrapper that contains all metadata
    	Dim xmpData As New Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta)
    
    	' create an instacne of Photoshop package and set photoshop attributes
    	Dim photoshopPackage As New Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage()
    	photoshopPackage.SetCity("London")
    	photoshopPackage.SetCountry("England")
    	photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb)
    	photoshopPackage.SetCreatedDate(DateTime.UtcNow)
    
    	' add photoshop package into XMP metadata
    	xmpData.AddPackage(photoshopPackage)
    
    	' create an instacne of DublinCore package and set dublinCore attributes
    	Dim dublinCorePackage As New Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage()
    	dublinCorePackage.SetAuthor("Charles Bukowski")
    	dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts")
    	dublinCorePackage.AddValue("dc:movie", "Barfly")
    
    	' add dublinCore Package into XMP metadata
    	xmpData.AddPackage(dublinCorePackage)
    
    	Using ms = New MemoryStream()
    		' update XMP metadata into image
    		image.XmpData = xmpData
    
    		' Save image on the disk or in memory stream
    		image.Save(ms)
    
    		ms.Seek(0, System.IO.SeekOrigin.Begin)
    
    		' Load the image from moemory stream or from disk to read/get the metadata
    		Using img = DirectCast(Aspose.Imaging.Image.Load(ms), TiffImage)
    			' getting the XMP metadata
    			Dim imgXmpData As Aspose.Imaging.Xmp.XmpPacketWrapper = img.XmpData
    					' use package data ...
    			For Each package As Aspose.Imaging.Xmp.XmpPackage In imgXmpData.Packages
    			Next
    		End Using
    	End Using
    End Using
    
    

    public by sherazam  2618  0  6  0

    How to Add Watermark to an Image inside .NET Applications

    // Enter here the actual content of the snippet.            
    // Adding a Watermark
    
    //[C# Code Sample]
    
    //Load an existing JPG image
    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(myDir + "sample.jpg"))
    {
    
        //Declare a String object with Watermark Text
        String theString = "45 Degree Rotated Text";
    
        //Create and initialize an instance of Graphics class
        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
    
        //Initialize an object of SizeF to store image Size
        Aspose.Imaging.SizeF sz = graphics.Image.Size;
    
        //Creates an instance of Font, initialize it with Font Face, Size and Style
        Aspose.Imaging.Font font = new Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold);
    
        //Create an instance of SolidBrush and set its various properties
        Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
        brush.Color = Aspose.Imaging.Color.Red;
        brush.Opacity = 0;
    
        //Initialize an object of StringFormat class and set its various properties
        Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat();
        format.Alignment = Aspose.Imaging.StringAlignment.Center;
        format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces;
    
        //Create an object of Matrix class for transformation
        Aspose.Imaging.Matrix matrix = new Aspose.Imaging.Matrix();
        //First a translation
        matrix.Translate(sz.Width / 2, sz.Height / 2);
        //Then a rotation
        matrix.Rotate(-45.0f);
    
        //Set the Transformation through Matrix
        graphics.Transform = matrix;
    
        //Draw the string on Image
        graphics.DrawString(theString, font, brush, 0, 0, format);
    
        //Save output to disk
        image.Save(myDir + "output.jpg");
    }
     
    //[VB.NET Code Sample]
    
    'Load an existing JPG image
    Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(myDir & "sample.jpg")
    
    	'Declare a String object with Watermark Text
    	Dim theString As String = "45 Degree Rotated Text"
    
    	'Create and initialize an instance of Graphics class
    	Dim graphics As New Aspose.Imaging.Graphics(image)
    
    	'Initialize an object of SizeF to store image Size
    	Dim sz As Aspose.Imaging.SizeF = graphics.Image.Size
    
    	'Creates an instance of Font, initialize it with Font Face, Size and Style
    	Dim font As New Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold)
    
    	'Create an instance of SolidBrush and set its various properties
    	Dim brush As New Aspose.Imaging.Brushes.SolidBrush()
    	brush.Color = Aspose.Imaging.Color.Red
    	brush.Opacity = 0
    
    	'Initialize an object of StringFormat class and set its various properties
    	Dim format As New Aspose.Imaging.StringFormat()
    	format.Alignment = Aspose.Imaging.StringAlignment.Center
    	format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces
    
    	'Create an object of Matrix class for transformation
    	Dim matrix As New Aspose.Imaging.Matrix()
    	'First a translation
    	matrix.Translate(sz.Width / 2, sz.Height / 2)
    	'Then a rotation
    	matrix.Rotate(-45.0f)
    
    	'Set the Transformation through Matrix
    	graphics.Transform = matrix
    
    	'Draw the string on Image
    	graphics.DrawString(theString, font, brush, 0, 0, format)
    
    	'Save output to disk
    	image.Save(myDir & "output.jpg")
    End Using
    
    

    public by sherazam  2488  0  5  0

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

    // 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
    
    

    List Complete ( 6 snippets total )

    • Public Snippets
    • Channels Snippets