←Select platform

CodecsWebpSaveOptions Class

Summary
Provides options specifically for saving WebP images.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class CodecsWebpSaveOptions 
@interface LTCodecsWebpSaveOptions : NSObject 
public class CodecsWebpSaveOptions 
public ref class CodecsWebpSaveOptions  
class CodecsWebpSaveOptions: 
Remarks

Obtain an instance of this class by getting the CodecsWebpOptions.Save property.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
using Leadtools.Pdf; 
 
public void CodecsWebpSaveOptionsExample() 
{ 
   // Saves an animated WEBP file. 
   // Stores all animation frames in a single RasterImage object. 
   string srcFile = Path.Combine(LEAD_VARS.ImagesDir, @"eye.gif"); 
   string dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"eye.webp"); 
 
   // Load all the pages in the same RasterImage object  
   using (RasterCodecs codecs = new RasterCodecs()) 
   using (RasterImage image = codecs.Load(srcFile, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1)) 
   { 
      using (CodecsImageInfo info = codecs.GetInformation(srcFile, true)) 
      { 
         codecs.Options.Webp.Save.AnimationWidth = info.Gif.AnimationWidth; 
         codecs.Options.Webp.Save.AnimationHeight = info.Gif.AnimationHeight; 
         codecs.Options.Webp.Save.UseAnimationBackground = info.Gif.HasAnimationBackground; 
         codecs.Options.Webp.Save.AnimationBackground = info.Gif.AnimationBackground; 
         codecs.Options.Webp.Save.UseAnimationLoop = info.Gif.HasAnimationLoop; 
         codecs.Options.Webp.Save.AnimationLoop = info.Gif.AnimationLoop; 
         codecs.Options.Webp.Save.QualityFactor = 0; // use lossless compression 
      } 
 
      // Retrieves Webp save options 
      CodecsWebpSaveOptions codecsWebpSaveOptions = codecs.Options.Webp.Save; 
      Debug.WriteLine($"AnimationWidth: {codecsWebpSaveOptions.AnimationWidth}"); 
 
      // delete the output file in case you run this code more than once 
      File.Delete(dstFile); 
      // save all the pages, appending each new page 
      codecs.Save(image, dstFile, RasterImageFormat.WebpAni, 0, 1, -1, 1, CodecsSavePageMode.Append); 
   } 
} 
 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.nio.file.Paths; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.MinMaxBitsCommand; 
 
 
// Saves an animated WEBP file. 
// Stores all animation frames in a single RasterImage object. 
public void codecsWebpSaveOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFile = combine(LEAD_VARS_IMAGES_DIR, "eye.gif"); 
   String dstFile = combine(LEAD_VARS_IMAGES_DIR, "eye.webp"); 
 
   // Load all the pages in the same RasterImage object 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.load(srcFile, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, -1); 
 
   CodecsImageInfo info = codecs.getInformation(srcFile, true); 
   codecs.getOptions().getWebp().getSave().setAnimationWidth(info.getGif().getAnimationWidth()); 
   codecs.getOptions().getWebp().getSave().setAnimationHeight(info.getGif().getAnimationHeight()); 
   codecs.getOptions().getWebp().getSave().setUseAnimationBackground(info.getGif().hasAnimationBackground()); 
   codecs.getOptions().getWebp().getSave().setAnimationBackground(info.getGif().getAnimationBackground()); 
   codecs.getOptions().getWebp().getSave().setUseAnimationLoop(info.getGif().hasAnimationLoop()); 
   codecs.getOptions().getWebp().getSave().setAnimationLoop(info.getGif().getAnimationLoop()); 
   codecs.getOptions().getWebp().getSave().setQualityFactor(0); // use lossless compression 
   info = null; 
 
   // Retrieves Webp save options 
   CodecsWebpSaveOptions codecsWebpSaveOptions = codecs.getOptions().getWebp().getSave(); 
   System.out.println("AnimationWidth: " + codecsWebpSaveOptions.getAnimationWidth()); 
 
   // delete the output file in case you run this code more than once 
   File file = new File(dstFile); 
   if (file.exists()) 
      file.delete(); 
 
   // save all the pages, appending each new page 
   codecs.save(image, dstFile, RasterImageFormat.WEBP_ANI, 0, 1, -1, 1, CodecsSavePageMode.APPEND); 
 
   assertTrue("File unsuccessfully saved to " + dstFile, (new File(dstFile)).exists()); 
   System.out.printf("File successfully saved to %s%n", dstFile); 
 
   image.dispose();; 
   codecs.dispose();; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.