Table of Contents

Class JpegImage

Namespace
Aspose.Imaging.FileFormats.Jpeg
Assembly
Aspose.Imaging.dll

Efficiently manipulate JPEG raster images with our API, offering support for various color profiles such as RGB and CMYK, customizable bits per pixel resolution, and processing of EXIF, JFIF, and XMP metadata containers. Enjoy automated rotation based on orientation data and choose from different compression levels, including lossless JPEG, to achieve optimal image quality and file size balance for your projects.

public sealed class JpegImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasJpegExifData, IHasExifData, IHasMetadata
Inheritance
JpegImage
Implements
Inherited Members

Constructors

JpegImage(JpegOptions, int, int)

Initialize a new JpegImage object with the provided JPEG options. This constructor empowers you to tailor various settings for the JPEG image, such as compression level, quality, and additional parameters, granting precise control over the resulting image format.

public JpegImage(JpegOptions jpegOptions, int width, int height)

Parameters

jpegOptions JpegOptions

The jpeg options.

width int

Image width.

height int

Image height.

JpegImage(RasterImage)

Initialize a new instance of the JpegImage class with a raster image parameter. This constructor provides a convenient way to create JPEG images directly from raster images, streamlining the workflow for working with JPEG images in your applications.

public JpegImage(RasterImage rasterImage)

Parameters

rasterImage RasterImage

The image to initialize pixel and palette data with.

JpegImage(Stream)

Initialize a JPEG image object with the JpegImage class using a stream parameter. This constructor simplifies the process of working with JPEG images, offering a straightforward approach for integrating them into your projects effortlessly.

public JpegImage(Stream stream)

Parameters

stream Stream

The stream to load image from and initialize pixel and palette data with.

JpegImage(int, int)

Create a new instance of the JpegImage class with the specified width and height parameters. This constructor allows you to create JPEG images with custom dimensions, giving you flexibility in managing image sizes in your application.

public JpegImage(int width, int height)

Parameters

width int

The image width.

height int

The image height.

JpegImage(string)

The JpegImage class initiates effortlessly by invoking its constructor with the specified path parameter. This constructor enables seamless creation of JPEG images, ensuring swift integration into your projects with ease.

public JpegImage(string path)

Parameters

path string

The path to load image from and initialize pixel and palette data with.

Properties

BitsPerPixel

Retrieve the pixel depth of the image effortlessly with this property, offering insights into the richness of color or grayscale representation. Whether it's a vibrant photograph or a monochrome illustration, this property provides crucial information about the image's visual complexity.

public override int BitsPerPixel { get; }

Property Value

int

The image bits per pixel count.

CmykColorProfile

The CMYK color profile associated with CMYK and YCCK JPEG images ensures precise color conversion and fidelity. It works in conjunction with the RGBColorProfile to guarantee accurate color representation across various devices and applications. This pairing is crucial for maintaining consistency in color rendering and achieving optimal image quality.

public StreamSource CmykColorProfile { get; set; }

Property Value

StreamSource

Comment

Manage JPEG file comments with this property, allowing you to add or retrieve descriptive annotations associated with the image. Whether it's tagging images with metadata or appending additional context, this property offers flexibility in organizing and categorizing your JPEG files.

public string Comment { get; set; }

Property Value

string

DestinationCmykColorProfile

The CMYK color profile is vital for the accurate color conversion of CMYK and YCCK JPEG images during the saving process. It works in tandem with the RGBColorProfile to ensure correct color representation, maintaining consistency and quality across different devices and software. This synchronization is crucial for achieving accurate and reliable color rendering in the final saved images.

public StreamSource DestinationCmykColorProfile { get; set; }

Property Value

StreamSource

DestinationRgbColorProfile

The RGBColorProfile is essential for the accurate color conversion of CMYK and YCCK JPEG images during the saving process. When paired with the CMYKColorProfile, it ensures that the colors are rendered correctly and maintains consistency across different devices and applications. This combination is crucial for preserving the intended color representation and achieving high-quality image output.

public StreamSource DestinationRgbColorProfile { get; set; }

Property Value

StreamSource

ExifData

Manage EXIF data with this property, allowing you to add or retrieve metadata associated with the image. Whether it's extracting information about the camera settings or modifying existing metadata, this property offers flexibility in managing the EXIF data container.

public JpegExifData ExifData { get; set; }

Property Value

JpegExifData

FileFormat

Retrieve the format of the image effortlessly with this property. It provides valuable insight into the file format, aiding in seamless integration and compatibility checks across various platforms and applications.

public override FileFormat FileFormat { get; }

Property Value

FileFormat

Height

Retrieve the height of the image effortlessly with this property. It provides quick access to the vertical dimension of the image, allowing you to efficiently determine its size and aspect ratio without the need for complex calculations or additional methods.

public override int Height { get; }

Property Value

int

The image height.

HorizontalResolution

This property grants you access to the horizontal resolution of the RasterImage, measured in pixels per inch. By setting or retrieving this value, you can precisely control the resolution of the image, ensuring it meets your specific requirements for quality and clarity.

public override double HorizontalResolution { get; set; }

Property Value

double

The horizontal resolution.

Remarks

Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

IgnoreEmbeddedColorProfile

Retrieves or modifies the flag denoting whether the embedded color profile is disregarded. By setting this flag, users can specify whether the default color profile should be used instead of the embedded one. This option ensures greater control over color management, facilitating adjustments for consistency and compatibility across various platforms and applications.

public bool IgnoreEmbeddedColorProfile { get; set; }

Property Value

bool

Jfif

This property allows you to access or modify the JFIF (JPEG File Interchange Format) data associated with the JPEG image. JFIF is a standard format for exchanging JPEG-compressed images between computers and other devices. By getting or setting this property, you can interact with the JFIF data, which may include information such as the image's resolution, aspect ratio, and thumbnail.

public JFIFData Jfif { get; set; }

Property Value

JFIFData

JpegOptions

Gain access to the JPEG options employed during the creation or loading of this JpegImage instance with ease. This property offers valuable details about the specific settings utilized, empowering users to understand and replicate image processing workflows effectively. Whether it's compression levels, quality settings, or other parameters, this property provides essential insights for seamless image manipulation.

public JpegOptions JpegOptions { get; }

Property Value

JpegOptions

The JPEG options.

RawDataFormat

This property retrieves the raw data format of the image, which indicates how the image data is structured and encoded. Understanding the raw data format is essential for processing or manipulating the image data effectively. It provides insights into the underlying representation of the image, such as whether it's compressed, encoded in a specific color space, or stored in a particular file format. Accessing this property allows you to gain valuable information about the image's data structure, enabling you to perform various operations or optimizations tailored to its specific format.

public override PixelDataFormat RawDataFormat { get; }

Property Value

PixelDataFormat

RgbColorProfile

The RGB color profile for CMYK and YCCK JPEG images ensures accurate color conversion and representation. It must be paired with the CMYKColorProfile to maintain consistency and fidelity in color rendering. This pairing is essential for applications that require precise color management and reproduction of images, ensuring that the RGB data is properly interpreted and displayed.

public StreamSource RgbColorProfile { get; set; }

Property Value

StreamSource

VerticalResolution

This property manages the vertical resolution, expressed in pixels per inch, for the associated RasterImage. Adjusting this resolution impacts the size and quality of the image when printed or displayed at a fixed physical size. By setting this property, you control how densely the image's pixels are packed vertically, affecting its overall sharpness and clarity.

public override double VerticalResolution { get; set; }

Property Value

double

The vertical resolution.

Remarks

Note by default this value is always 72 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

Width

This property retrieves the width of the image, expressed in pixels. It provides essential information about the image's dimensions, enabling accurate rendering, manipulation, or display of the image data.

public override int Width { get; }

Property Value

int

The image width.

XmpData

Gets or sets XMP metadata, enabling seamless integration of descriptive information into the image file. Whether you're extracting existing XMP metadata or updating it with new information, this property simplifies the management of extended metadata, ensuring compatibility with various applications and workflows.

public override XmpPacketWrapper XmpData { get; set; }

Property Value

XmpPacketWrapper

The XMP metadata.

Methods

AutoRotate()

Automatically rotates the image based on orientation data extracted from Exif metadata. This method ensures that images are displayed in the correct orientation, enhancing user experience and eliminating the need for manual adjustments. By analyzing Exif information, the image is rotated accordingly, providing a seamless viewing experience across different platforms and devices. This automated rotation process simplifies image handling and improves overall usability, especially when dealing with large batches of images with varying orientations.

public void AutoRotate()

Exceptions

ArgumentOutOfRangeException

The 'Orientation' value of 'JpegExifData' is out of allowed range [1...8], so auto-rotation can not be applied.

GetModifyDate(bool)

Retrieves the date and time when the resource image underwent its latest modification. This method provides valuable metadata, enabling users to track and manage updates to the image file effectively. By accessing this information, users can ensure the integrity and currency of their image assets, facilitating informed decision-making regarding image usage and maintenance.

public override DateTime GetModifyDate(bool useDefault)

Parameters

useDefault bool

if set to true uses the information from FileInfo as default value.

Returns

DateTime

The date and time the resource image was last modified.

ReleaseManagedResources()

Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been already released.

protected override void ReleaseManagedResources()

RemoveMetadata()

Removes this image instance metadata by setting this XmpData and ExifData values to null.

public override void RemoveMetadata()

SaveData(Stream)

protected override void SaveData(Stream stream)

Parameters

stream Stream

SetResolution(double, double)

Establishes the resolution for the specified RasterImage, ensuring accurate scaling and printing capabilities. This method empowers users to tailor the image resolution to suit their specific requirements, whether for digital display or physical reproduction. By setting the resolution, users can optimize image quality and ensure compatibility with various output devices and mediums, enhancing the overall visual experience and usability of the image.

public override void SetResolution(double dpiX, double dpiY)

Parameters

dpiX double

The horizontal resolution, in dots per inch, of the RasterImage.

dpiY double

The vertical resolution, in dots per inch, of the RasterImage.

UpdateDimensions(int, int)

protected override void UpdateDimensions(int newWidth, int newHeight)

Parameters

newWidth int
newHeight int

UpdateMetadata()

Updates the image metadata.

protected override void UpdateMetadata()