←Select platform

QualityFactor Property

Summary
Gets and sets the Quality Factor (QFactor) to use when saving WebP images (single-frame or animation).
Syntax
C#
Objective-C
C++/CLI
Java
Python
public int QualityFactor { get; set; } 
@property (nonatomic, assign) NSInteger qualityFactor; 
public int getQualityFactor() 
public void setQualityFactor(int value) 
public: 
property int QualityFactor { 
   int get(); 
   void set (    int ); 
} 
QualityFactor # get and set (CodecsWebpSaveOptions) 

Property Value

The Quality Factor to use when saving WebP compressed images.

Value Description
0 Lossless JPEG
1 Highest quality
2-254 The lower the value, the higher the quality. The higher the value, the higher the compression. The default value is 20.
255 Highest compression
Remarks

Select the lossy compression by setting a value from 1 to 255, where 1 is the highest quality and 255 is the most compression. Use 0 to produce lossless WebP files.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
 
public void TestSaveWebpExample() 
{ 
   // This example saves 3 files with various stamp settings and quality factors 
   string srcFile = Path.Combine(LEAD_VARS.ImagesDir, @"sample1.cmp"); 
   string dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"out-"); 
 
   using (RasterCodecs codecs = new RasterCodecs()) 
   using (RasterImage image = codecs.Load(srcFile, 1)) 
   { 
      // CodecsWebpOptions & CodecsWebpSaveOptions reference 
      codecs.Options.Webp.Save.SaveWithStamp = true; 
      codecs.Options.Webp.Save.StampBitsPerPixel = 24; 
 
      codecs.Options.Webp.Save.QualityFactor = 20; 
      codecs.Options.Webp.Save.StampWidth = 160; 
      codecs.Options.Webp.Save.StampHeight = 120; 
      // this file should have a stamp that is 160x120 
      codecs.Save(image, dstFile + "stamp160x120-q20.webp", RasterImageFormat.Webp, 0); 
 
      // this file should have a stamp that is 240x200 
      codecs.Options.Webp.Save.QualityFactor = 120; 
      codecs.Options.Webp.Save.StampWidth = 240; 
      codecs.Options.Webp.Save.StampHeight = 200; 
      codecs.Save(image, dstFile + "stamp240x200-q120.webp", RasterImageFormat.Webp, 0); 
 
      // this file should have no stamp 
      codecs.Options.Webp.Save.SaveWithStamp = false; 
      codecs.Options.Webp.Save.QualityFactor = 0; 
      codecs.Save(image, dstFile + "NoStamp-lossless.webp", RasterImageFormat.Webp, 0); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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