Class WebPImage
- Namespace
- Aspose.Imaging.FileFormats.Webp
- Assembly
- Aspose.Imaging.dll
Manipulate WebP raster images with our API, using its modern features for both lossless and lossy compression, ensuring optimal image quality with reduced file sizes. Seamlessly handle extended file formats, animations, and alpha channels, while easily updating dimensions, resizing proportionally, cropping, rotating, applying filters, adjusting image parameters, and converting to other image formats for versatile web image optimization.
public sealed class WebPImage : RasterCachedMultipageImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata, IMultipageImageExt, IMultipageImage
- Inheritance
-
WebPImage
- Implements
- Inherited Members
Constructors
WebPImage(RasterImage)
Instantiate a new instance of the WebPImage class, initialized from a provided rasterImage object. This constructor allows for seamless conversion of raster images to WebP format, enabling efficient handling and manipulation of image data within your application.
public WebPImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImageThe raster image.
WebPImage(RasterImage, LoadOptions)
Create a new instance of the WebPImage class using a rasterImage object and specified load options, enabling flexible handling of image data. Utilize this constructor to seamlessly initialize WebP image objects from raster images while customizing loading parameters according to your application's requirements.
public WebPImage(RasterImage rasterImage, LoadOptions loadOptions)
Parameters
rasterImage
RasterImageThe raster image.
loadOptions
LoadOptionsThe load options.
WebPImage(Stream)
Instantiate a new instance of the WebPImage class, initialized from a provided stream source. Utilize this constructor to seamlessly create WebP image objects directly from streams, enabling efficient handling and manipulation of WebP image data within your application.
public WebPImage(Stream stream)
Parameters
stream
StreamThe stream WebP image.
WebPImage(Stream, LoadOptions)
Create a new instance of the WebPImage class using a stream and specified load options, facilitating versatile handling of WebP image data. Incorporate this constructor to seamlessly initialize WebP image objects from streams while customizing loading parameters as needed within your application.
public WebPImage(Stream stream, LoadOptions loadOptions)
Parameters
stream
StreamThe stream WebP image.
loadOptions
LoadOptionsThe load options.
WebPImage(int, int, WebPOptions)
Instantiate a new instance of the WebPImage class with an empty image of specified width and height dimensions. This constructor allows for the creation of blank WebP images, providing a foundation for subsequent image manipulation and content generation within your application.
public WebPImage(int width, int height, WebPOptions options)
Parameters
width
intThe image width
height
intThe image height.
options
WebPOptionsThe options.
WebPImage(int, int, WebPOptions, LoadOptions)
Create a new instance of the WebPImage class with an empty image and specified load options. This constructor allows for the initialization of WebP images with customizable loading parameters, providing flexibility in image creation and manipulation within your application.
public WebPImage(int width, int height, WebPOptions options, LoadOptions loadOptions)
Parameters
width
intThe image width
height
intThe image height.
options
WebPOptionsThe options.
loadOptions
LoadOptionsThe load options.
WebPImage(string)
Instantiate a fresh instance of the WebPImage class, initialized from a provided file source. Utilize this constructor to seamlessly create WebP image objects directly from files, streamlining the process of loading and manipulating WebP image data within your application.
public WebPImage(string path)
Parameters
path
stringThe path to file WebP Image
WebPImage(string, LoadOptions)
Create a new instance of the WebPImage class using a file and specified load options, facilitating flexible handling of WebP image data. Utilize this constructor to seamlessly initialize WebP image objects from files while customizing loading parameters according to your application's requirements.
public WebPImage(string path, LoadOptions loadOptions)
Parameters
path
stringThe path to file WebP Image
loadOptions
LoadOptionsThe load options.
Properties
FileFormat
Access the file format value associated with the image, providing information about the format in which the image is stored. Utilize this property to determine the file format of the image, facilitating compatibility checks and format-specific processing within your application.
public override FileFormat FileFormat { get; }
Property Value
HasAlpha
Retrieve whether the image contains an alpha channel, indicating the presence of transparency information. Utilize this property to determine whether the image includes transparency, enabling appropriate handling and processing of alpha-related operations within your application.
public override bool HasAlpha { get; }
Property Value
- bool
The Has alpha channel.
Options
Retrieve or modify the options associated with the specified property, enabling fine-tuned customization of behavior and settings. Utilize this property to seamlessly access and manipulate configurable parameters, facilitating versatile control and optimization within your application's functionality.
public WebPOptions Options { get; }
Property Value
- WebPOptions
The options.
PageCount
Retrieve the total count of pages within the specified document, facilitating efficient navigation and management of multi-page content. Incorporate this functionality to enhance user experience, enabling seamless access to comprehensive document structures.
public override int PageCount { get; }
Property Value
- int
The page count.
PageExportingAction
Access or modify the page exporting action, which defines the specific action to be executed before each page is saved. Please note that setting this property will automatically release page resources after execution. Utilize this feature to perform custom actions or cleanup tasks before exporting each page, ensuring optimal resource management and desired behavior during image saving operations within your application.
public override PageExportingAction PageExportingAction { get; set; }
Property Value
- PageExportingAction
The page exporting action.
Pages
Access the WebP blocks within the image, allowing detailed examination or manipulation of the underlying block structure. Utilize this property to analyze or modify individual blocks within the WebP image data, facilitating advanced image processing techniques within your application.
public override Image[] Pages { get; }
Property Value
- Image[]
The blocks.
Methods
AddBlock(IFrame)
Incorporate a new WebP block into the image, enriching its content and facilitating advanced image manipulation. Integrate this method to dynamically enhance the structure and complexity of the WebP image data within your application, enabling precise control and optimization of image rendering.
public void AddBlock(IFrame block)
Parameters
block
IFrameThe Webp block to add.
AddPage(RasterImage)
Append a new page to the image, expanding its content and accommodating additional visual elements. Integrate this method to facilitate dynamic page management within your application, enabling seamless creation and augmentation of multi-page documents or images.
public void AddPage(RasterImage page)
Parameters
page
RasterImageThe page to add.
Exceptions
- ArgumentNullException
page
is null.
AdjustBrightness(int)
Implement brightness
adjustment for the image, allowing the
modification of overall luminance levels. Incorporate this method into your image
processing workflow to enhance visibility and improve the visual quality of images
within your application.
public override void AdjustBrightness(int brightness)
Parameters
brightness
intBrightness value.
AdjustContrast(float)
Enhance the contrast of the Image, amplifying the differences between light and dark areas. Integrate this method into your image processing workflow to improve visual clarity and overall image quality within your application.
public override void AdjustContrast(float contrast)
Parameters
contrast
floatContrast value (in range [-100; 100])
AdjustGamma(float)
Apply gamma correction to the image, adjusting pixel intensities to achieve desired brightness and color balance. Incorporate this method into your image processing workflow to enhance visual quality and improve the accuracy of subsequent analysis or display tasks within your application.
public override void AdjustGamma(float gamma)
Parameters
gamma
floatGamma for red, green and blue channels coefficient
AdjustGamma(float, float, float)
Perform gamma correction on the image using individual coefficients for the red, green, and blue channels, allowing for fine-tuned adjustments of color balance and contrast. Integrate this method into your image processing pipeline to achieve precise control over color rendering and enhance visual fidelity within your application.
public override void AdjustGamma(float gammaRed, float gammaGreen, float gammaBlue)
Parameters
gammaRed
floatGamma for red channel coefficient
gammaGreen
floatGamma for green channel coefficient
gammaBlue
floatGamma for blue channel coefficient
BinarizeBradley(double, int)
Apply binarization to the image using Bradley's adaptive thresholding algorithm with integral image thresholding. This method dynamically computes local thresholds based on the image's neighborhood, enhancing adaptability to varying lighting conditions and ensuring robust segmentation for subsequent processing tasks within your application.
public override void BinarizeBradley(double brightnessDifference, int windowSize)
Parameters
brightnessDifference
doubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
windowSize
intThe size of s x s window of pixels centered around this pixel
BinarizeFixed(byte)
Perform binarization on the image using a predefined threshold value, converting it into a binary image where pixels are classified as foreground or background based on their intensity relative to the threshold. Integrate this method into your image processing workflow to facilitate segmentation and feature extraction tasks, enhancing the accuracy and efficiency of subsequent analysis within your application.
public override void BinarizeFixed(byte threshold)
Parameters
threshold
byteThreshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.
BinarizeOtsu()
Perform binarization on the image using Otsu's thresholding method, automatically determining the optimal threshold value based on the image's histogram. Integrate this method into your image processing workflow to achieve effective segmentation and feature extraction, enhancing the accuracy and reliability of image analysis tasks within your application.
public override void BinarizeOtsu()
ClearBlocks()
Clear all existing WebP blocks from the image, facilitating a clean slate for subsequent modifications or additions. Utilize this method to effectively reset the block structure within the WebP image data, ensuring optimal management and organization of image content within your application.
public void ClearBlocks()
Crop(Rectangle)
Crop the image using a specified rectangle region, removing unwanted portions while retaining the desired content. Integrate this method into your image processing workflow to precisely extract and focus on specific areas of interest within the image, enhancing clarity and composition for various applications.
public override void Crop(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle.
Crop(int, int, int, int)
Crop the image by applying left, right, top, and bottom shifts, effectively selecting a region of interest within the image. Utilize this method to dynamically extract desired portions of the image while adjusting its composition and focus according to your application's requirements.
public override void Crop(int leftShift, int rightShift, int topShift, int bottomShift)
Parameters
leftShift
intThe left shift.
rightShift
intThe right shift.
topShift
intThe top shift.
bottomShift
intThe bottom shift.
Dither(DitheringMethod, int, IColorPalette)
Perform dithering on the current image to reduce color banding and enhance visual quality. Integrate this method into your image processing workflow to achieve smoother transitions between colors and improve the overall appearance of the image within your application.
public override void Dither(DitheringMethod ditheringMethod, int bitsCount, IColorPalette customPalette)
Parameters
ditheringMethod
DitheringMethodThe dithering method.
bitsCount
intThe final bits count for dithering.
customPalette
IColorPaletteThe custom palette for dithering.
Filter(Rectangle, FilterOptionsBase)
Filter the content within the specified rectangle, applying a designated image processing filter to enhance or modify the selected region. Integrate this method into your image manipulation workflow to achieve targeted enhancements or transformations within your application.
public override void Filter(Rectangle rectangle, FilterOptionsBase options)
Parameters
rectangle
RectangleThe rectangle.
options
FilterOptionsBaseThe options.
Grayscale()
Convert the image to its grayscale representation, transforming it into a single-channel image where each pixel represents intensity or luminance. Integrate this method into your image processing pipeline to simplify analysis and enhance compatibility with grayscale-based algorithms, facilitating various computer vision and image analysis tasks within your application.
public override void Grayscale()
InsertBlock(int, IFrame)
Insert a new WebP block at the specified index within the image, enabling precise control over the block sequence. Integrate this method to seamlessly incorporate additional WebP blocks into the image data structure, facilitating advanced image processing and optimization within your application.
public void InsertBlock(int index, IFrame block)
Parameters
index
intThe zero-based element, at which
block
will be inserted.block
IFrameThe Webp block to add.
ReleaseManagedResources()
protected override void ReleaseManagedResources()
RemoveBlock(IFrame)
Remove the specified WebP block from the image, facilitating efficient management of image data structure. Utilize this method to streamline image processing workflows by eliminating unnecessary blocks or components within your application.
public void RemoveBlock(IFrame block)
Parameters
block
IFrameThe block to remove.
Remarks
Note: do not forget to Dispose the block
if you
will not add it to some other WebPImage.
Resize(int, int, ImageResizeSettings)
Resize the image according to specified settings, enabling precise control over dimensions, aspect ratio, and scaling behavior. Integrate this method into your image processing workflow to achieve customized resizing operations tailored to the specific requirements of your application.
public override void Resize(int newWidth, int newHeight, ImageResizeSettings settings)
Parameters
newWidth
intThe new width.
newHeight
intThe new height.
settings
ImageResizeSettingsThe resize settings.
Resize(int, int, ResizeType)
Resize the image, adjusting its dimensions while preserving the aspect ratio. Integrate this method into your image processing workflow to dynamically scale images to fit various display or storage requirements within your application.
public override void Resize(int newWidth, int newHeight, ResizeType resizeType)
Parameters
newWidth
intThe new width.
newHeight
intThe new height.
resizeType
ResizeTypeThe resize type.
ResizeHeightProportionally(int, ResizeType)
Adjust the height of the image proportionally, while preserving its aspect ratio for consistent resizing. Integrate this method into your image processing workflow to dynamically resize images with uniform proportions, ensuring optimal display or storage within your application.
public override void ResizeHeightProportionally(int newHeight, ResizeType resizeType)
Parameters
newHeight
intThe new height.
resizeType
ResizeTypeType of the resize.
ResizeWidthProportionally(int, ResizeType)
Proportionally adjust the width of the image while maintaining its aspect ratio. Integrate this method into your image processing workflow to dynamically resize images with consistent proportions, ensuring optimal display or storage within your application.
public override void ResizeWidthProportionally(int newWidth, ResizeType resizeType)
Parameters
newWidth
intThe new width.
resizeType
ResizeTypeType of the resize.
Rotate(float, bool, Color)
Rotate the image around its center by a specified angle, while proportionally resizing it and applying specified background color parameters. Incorporate this method into your image processing workflow to achieve precise transformations with customizable background colors, ensuring optimal visual presentation within your application.
public override void Rotate(float angle, bool resizeProportionally, Color backgroundColor)
Parameters
angle
floatThe rotate angle in degrees. Positive values will rotate clockwise.
resizeProportionally
boolif set to
true
you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.backgroundColor
ColorColor of the background.
RotateFlip(RotateFlipType)
Apply rotation, flipping, or both operations exclusively to the active frame within the image. Integrate this method into your image processing workflow to achieve precise manipulation of individual frames, enhancing flexibility and control over frame transformations within your application.
public override void RotateFlip(RotateFlipType rotateFlipType)
Parameters
rotateFlipType
RotateFlipTypeThe rotate flip type.
SaveData(Stream)
protected override void SaveData(Stream stream)
Parameters
stream
Stream
UpdateDimensions(int, int)
protected override void UpdateDimensions(int newWidth, int newHeight)