Class JpegImage

Class JpegImage

Namespace: Aspose.Imaging.FileFormats.Jpeg
Assembly: Aspose.Imaging.dll (25.7.0)

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

[JsonObject(MemberSerialization.OptIn)]
    public sealed class JpegImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasJpegExifData, IHasExifData, IHasMetadata
    {
    }

Inheritance

object DisposableObject DataStreamSupporter Image RasterImage RasterCachedImage JpegImage

Implements

IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IHasXmpData , IHasJpegExifData , IHasExifData , IHasMetadata

Inherited Members

RasterCachedImage.CacheData() , RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedImage.Resize(int, int, ResizeType) , RasterCachedImage.Resize(int, int, ImageResizeSettings) , RasterCachedImage.RotateFlip(RotateFlipType) , RasterCachedImage.Rotate(float, bool, Color) , RasterCachedImage.Crop(Rectangle) , RasterCachedImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedImage.Grayscale() , RasterCachedImage.NormalizeHistogram() , RasterCachedImage.BinarizeFixed(byte) , RasterCachedImage.BinarizeOtsu() , RasterCachedImage.BinarizeBradley(double, int) , RasterCachedImage.BinarizeBradley(double) , RasterCachedImage.AdjustBrightness(int) , RasterCachedImage.AdjustContrast(float) , RasterCachedImage.AdjustGamma(float, float, float) , RasterCachedImage.AdjustGamma(float) , RasterCachedImage.IsCached , RasterImage.RemoveMetadata() , RasterImage.Save(Stream, ImageOptionsBase, Rectangle) , RasterImage.GetModifyDate(bool) , RasterImage.Dither(DitheringMethod, int) , RasterImage.Dither(DitheringMethod, int, IColorPalette) , RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) , RasterImage.GetDefaultArgb32Pixels(Rectangle) , RasterImage.GetDefaultRawData(Rectangle, RawDataSettings) , RasterImage.GetArgb32Pixel(int, int) , RasterImage.GetPixel(int, int) , RasterImage.SetArgb32Pixel(int, int, int) , RasterImage.SetPixel(int, int, Color) , RasterImage.ReadScanLine(int) , RasterImage.ReadArgb32ScanLine(int) , RasterImage.WriteScanLine(int, Color[]) , RasterImage.WriteArgb32ScanLine(int, int[]) , RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader) , RasterImage.LoadArgb32Pixels(Rectangle) , RasterImage.LoadArgb64Pixels(Rectangle) , RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) , RasterImage.LoadPixels(Rectangle) , RasterImage.LoadCmykPixels(Rectangle) , RasterImage.LoadCmyk32Pixels(Rectangle) , RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings) , RasterImage.SaveArgb32Pixels(Rectangle, int[]) , RasterImage.SavePixels(Rectangle, Color[]) , RasterImage.SaveCmykPixels(Rectangle, CmykColor[]) , RasterImage.SaveCmyk32Pixels(Rectangle, int[]) , RasterImage.SetResolution(double, double) , RasterImage.SetPalette(IColorPalette, bool) , RasterImage.Resize(int, int, ImageResizeSettings) , RasterImage.Rotate(float, bool, Color) , RasterImage.Rotate(float) , RasterImage.BinarizeFixed(byte) , RasterImage.BinarizeOtsu() , RasterImage.BinarizeBradley(double) , RasterImage.BinarizeBradley(double, int) , RasterImage.Blend(Point, RasterImage, Rectangle, byte) , RasterImage.Blend(Point, RasterImage, byte) , RasterImage.Grayscale() , RasterImage.NormalizeHistogram() , RasterImage.AdjustBrightness(int) , RasterImage.AdjustContrast(float) , RasterImage.AdjustGamma(float, float, float) , RasterImage.AdjustGamma(float) , RasterImage.GetSkewAngle() , RasterImage.NormalizeAngle() , RasterImage.NormalizeAngle(bool, Color) , RasterImage.Filter(Rectangle, FilterOptionsBase) , RasterImage.ReplaceColor(Color, byte, Color) , RasterImage.ReplaceColor(int, byte, int) , RasterImage.ReplaceNonTransparentColors(Color) , RasterImage.ReplaceNonTransparentColors(int) , RasterImage.ToBitmap() , RasterImage.PremultiplyComponents , RasterImage.UseRawData , RasterImage.UpdateXmpData , RasterImage.XmpData , RasterImage.RawIndexedColorConverter , RasterImage.RawCustomColorConverter , RasterImage.RawFallbackIndex , RasterImage.RawDataSettings , RasterImage.UsePalette , RasterImage.RawDataFormat , RasterImage.RawLineSize , RasterImage.IsRawDataAvailable , RasterImage.HorizontalResolution , RasterImage.VerticalResolution , RasterImage.HasTransparentColor , RasterImage.HasAlpha , RasterImage.TransparentColor , RasterImage.ImageOpacity , Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.Disposed , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Access camera manufacturer maker notes in Jpeg image.

using (var image = JpegImage.Load("Sample.jpg"))
   {
       foreach (var makerNote in image.ExifData.MakerNotes)
       {
           Console.WriteLine("Name = {0}, Value = {1}", makerNote.Name, makerNote.Value);
       }
   }

The example shows how to load a JpegImage from a file.

string dir = "c:\\temp\\";
   using (var jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(dir + "sample.jpg"))
   {
       jpegImage.Save(dir + "sample.output.jpg");
   }

Constructors

JpegImage(string)

The Aspose.Imaging.FileFormats.Jpeg.JpegImage class initiates effortlessly by invoking itsconstructor with the specified path parameter. This constructor enables seamlesscreation 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.

Examples

The example shows how to load a JpegImage from a file.

string dir = "c:\\temp\\";
   using (var jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(dir + "sample.jpg"))
   {
       jpegImage.Save(dir + "sample.output.jpg");
   }

JpegImage(Stream)

Initialize a JPEG image object with the Aspose.Imaging.FileFormats.Jpeg.JpegImage class using astream parameter. This constructor simplifies the process of working with JPEGimages, offering a straightforward approach for integrating them into your projectseffortlessly.

public JpegImage(Stream stream)
   {
   }

Parameters

stream Stream

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

Examples

The example shows how to load a JpegImage from a file stream.

string dir = "c:\\temp\\";
   using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.jpg"))
   {
       using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(stream))
       {
           jpegImage.Save(dir + "sample.output.jpg");
       }
   }

JpegImage(RasterImage)

Initialize a new instance of the Aspose.Imaging.FileFormats.Jpeg.JpegImage class with a raster imageparameter. This constructor provides a convenient way to create JPEG imagesdirectly from raster images, streamlining the workflow for working with JPEG imagesin your applications.

public JpegImage(RasterImage rasterImage)
   {
      this.RasterImage = rasterImage;
      SaveFormat = ImageFormat.Jpeg;
      Initialize();
   }

Parameters

rasterImage RasterImage

The image to initialize pixel and palette data with.

Examples

The example shows how to load a JpegImage from another RasterImage.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), false);
   using (Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(createOptions, 100, 100))
   {
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(rasterImage);
       Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
       graphics.FillRectangle(brush, rasterImage.Bounds);
       using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(rasterImage))
       {
           jpegImage.Save(dir + "output.jpg");
       }
   }

JpegImage(int, int)

Create a new instance of the Aspose.Imaging.FileFormats.Jpeg.JpegImage class with the specified widthand height parameters. This constructor allows you to create JPEG images withcustom 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.

Examples

The following example shows how to create JPEG image of the specified size.

string dir = "c:\\temp\\";
   using (var jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(100, 100))
   {
       jpegImage.Save(dir + "output.jpg");
   }

The following example loads a BMP image and saves it to JPEG using various save options.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
   {
       Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
       saveOptions.BitsPerChannel = 8;
       saveOptions.CompressionType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionMode.Progressive;
       saveOptions.Quality = 100;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ResolutionUnit = Aspose.Imaging.ResolutionUnit.Inch;
       saveOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.Grayscale;
       saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.Create8BitGrayscale(false);
       image.Save(dir + "sample.palettized.jpg", saveOptions);
   }

JpegImage(JpegOptions, int, int)

Initialize a new Aspose.Imaging.FileFormats.Jpeg.JpegImage object with the provided JPEG options.This constructor empowers you to tailor various settings for the JPEG image, suchas compression level, quality, and additional parameters, granting precise controlover 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.

Examples

The following example loads a BMP image and saves it to JPEG using various save options.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
   {
       Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
       saveOptions.BitsPerChannel = 8;
       saveOptions.CompressionType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionMode.Progressive;
       saveOptions.Quality = 100;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ResolutionUnit = Aspose.Imaging.ResolutionUnit.Inch;
       saveOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.Grayscale;
       saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.Create8BitGrayscale(false);
       image.Save(dir + "sample.palettized.jpg", saveOptions);
   }

The following example shows how to create JPEG image of the specified size with the specified parameters.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.JpegOptions createOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
   createOptions.BitsPerChannel = 8;
   createOptions.CompressionType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionMode.Progressive;
   createOptions.Quality = 100;
   createOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
   createOptions.ResolutionUnit = Aspose.Imaging.ResolutionUnit.Inch;
   createOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.YCbCr;
   using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(createOptions, 100, 100))
   {
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(jpegImage);
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(jpegImage.Width, jpegImage.Height),
           Aspose.Imaging.Color.Yellow,
           Aspose.Imaging.Color.Blue);
       graphics.FillRectangle(gradientBrush, jpegImage.Bounds);
       jpegImage.Save(dir + "output.explicitoptions.jpg");
   }

Properties

BitsPerPixel

Retrieve the pixel depth of the image effortlessly with this property, offeringinsights into the richness of color or grayscale representation. Whether it’s avibrant photograph or a monochrome illustration, this property provides crucialinformation about the image’s visual complexity.

public override int
    BitsPerPixel
    {
        get;
    }

Property Value

int

CmykColorProfile

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

public Stream SourceForCmykColorProfile { get; set; }

Property Value

StreamSource

Examples

The following example loads PNG and saves it to CMYK JPEG using custom ICC profile. Then loads CMYK JPEG and saves it back to PNG. The color conversion from RGB to CMYK and from CMYK to RGB is performed using custom ICC profiles.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Png.PngImage image = (Aspose.Imaging.FileFormats.Png.PngImage)Image.Load(dir + "sample.png"))
   {
       using (System.IO.Stream rgbProfileStream = System.IO.File.OpenRead(dir + "eciRGB_v2.icc"))
       using (System.IO.Stream cmykProfileStream = System.IO.File.OpenRead(dir + "ISOcoated_v2_FullGamut4.icc"))
       {
           Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
           saveOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.Cmyk;
           saveOptions.RgbColorProfile = new Aspose.Imaging.Sources.StreamSource(rgbProfileStream);
           saveOptions.CmykColorProfile = new Aspose.Imaging.Sources.StreamSource(cmykProfileStream);
           image.Save(dir + "output.cmyk.jpg", saveOptions);
       }
   }
   using (Aspose.Imaging.FileFormats.Jpeg.JpegImage image = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)Image.Load(dir + "output.cmyk.jpg"))
   {
       using (System.IO.Stream rgbProfileStream = System.IO.File.OpenRead(dir + "eciRGB_v2.icc"))
       using (System.IO.Stream cmykProfileStream = System.IO.File.OpenRead(dir + "ISOcoated_v2_FullGamut4.icc"))
       {
           image.RgbColorProfile = new Aspose.Imaging.Sources.StreamSource(rgbProfileStream);
           image.CmykColorProfile = new Aspose.Imaging.Sources.StreamSource(cmykProfileStream);
           Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
           image.Save(dir + "output.rgb.png", saveOptions);
       }
   }

Comment

Manage JPEG file comments with this property, allowing you to add or retrievedescriptive annotations associated with the image. Whether it’s tagging images withmetadata or appending additional context, this property offers flexibility inorganizing 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 YCCKJPEG images during the saving process. It works in tandem with the RGBColorProfileto ensure correct color representation, maintaining consistency and quality acrossdifferent devices and software. This synchronization is crucial for achievingaccurate and reliable color rendering in the final saved images.

public Stream SourceDestinationCmykColorProfile { get; set; }

Property Value

StreamSource

DestinationRgbColorProfile

The RGBColorProfile is essential for the accurate color conversion of CMYK and YCCKJPEG images during the saving process. When paired with the CMYKColorProfile, itensures that the colors are rendered correctly and maintains consistency acrossdifferent devices and applications. This combination is crucial for preserving theintended color representation and achieving high-quality image output.

public Stream SourceRgbColorProfile { get; set; }

Property Value

StreamSource

ExifData

Manage EXIF data with this property, allowing you to add or retrieve metadataassociated with the image. Whether it’s extracting information about the camerasettings or modifying existing metadata, this property offers flexibility inmanaging the EXIF data container.

public JpegExifData ExifData
    {
        get;
        set;
    }

Property Value

JpegExifData

Examples

The following example shows how to extract EXIF tags from a JPEG image.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Jpeg.JpegImage image = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)Image.Load(dir + "original.jpg"))
   {
       Aspose.Imaging.Exif.ExifData exifData = image.ExifData;
       System.Console.WriteLine("The general EXIF data");
       System.Console.WriteLine("------------------------------------------");
       if (exifData != null)
       {
           System.Console.WriteLine("The EXIF version: {0}", exifData.ExifVersion);
           System.Console.WriteLine("The camera serial number: {0}", exifData.BodySerialNumber);
           System.Console.WriteLine("The color space: {0}", exifData.ColorSpace);
           System.Console.WriteLine("The brightness: {0}", exifData.BrightnessValue);
           System.Console.WriteLine("The contrast: {0}", exifData.Contrast);
           System.Console.WriteLine("The gamma: {0}", exifData.Gamma);
           System.Console.WriteLine("The sharpness: {0}", exifData.Sharpness);
           System.Console.WriteLine("The aperture: {0}", exifData.ApertureValue);
           System.Console.WriteLine("The exposure mode: {0}", exifData.ExposureMode);
           System.Console.WriteLine("The exposure bias: {0}", exifData.ExposureBiasValue);
           System.Console.WriteLine("The exposure time: {0}", exifData.ExposureTime);
           System.Console.WriteLine("The focal length: {0}", exifData.FocalLength);
           System.Console.WriteLine("The focal plane resolution unit: {0}", exifData.FocalPlaneResolutionUnit);
           System.Console.WriteLine("The lens model: {0}", exifData.LensModel);
           System.Console.WriteLine("The shutter speed: {0}", exifData.ShutterSpeedValue);
       }
       System.Console.WriteLine(); // Added blank line for readability
       System.Console.WriteLine("The JPEG EXIF data");
       System.Console.WriteLine("------------------------------------------");
       Aspose.Imaging.Exif.JpegExifData jpegExifData = image.ExifData as Aspose.Imaging.Exif.JpegExifData;
       if (jpegExifData != null)
       {
           System.Console.WriteLine("The camera manufacturer: {0}", jpegExifData.Make);
           System.Console.WriteLine("The camera model: {0}", jpegExifData.Model);
           System.Console.WriteLine("The photometric interpretation: {0}", jpegExifData.PhotometricInterpretation);
           System.Console.WriteLine("The artist: {0}", jpegExifData.Artist);
           System.Console.WriteLine("The copyright: {0}", jpegExifData.Copyright);
           System.Console.WriteLine("The image description: {0}", jpegExifData.ImageDescription);
           System.Console.WriteLine("The orientation: {0}", jpegExifData.Orientation);
           System.Console.WriteLine("The software: {0}", jpegExifData.Software);
       }
   }

FileFormat

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

public override FileFormat
    {
        get;
    }

Property Value

FileFormat

Height

Retrieve the height of the image effortlessly with this property. It provides quickaccess to the vertical dimension of the image, allowing you to efficientlydetermine its size and aspect ratio without the need for complex calculations oradditional methods.

public override int Height
   {
      get;
   }

Property Value

int

HorizontalResolution

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

public override double HorizontalResolution
{
    get;
    set;
}

Property Value

double

Examples

The following example shows how to set horizontal/vertical resolution of a JPEG image.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
   {
       Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)image;
       double horizontalResolution = jpegImage.HorizontalResolution;
       double verticalResolution = jpegImage.VerticalResolution;
       System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
       System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
       if (horizontalResolution != 96.0 || verticalResolution != 96.0)
       {
           System.Console.WriteLine("Set resolution values to 96 dpi");
           jpegImage.SetResolution(96.0, 96.0);
           System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", jpegImage.HorizontalResolution);
           System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", jpegImage.VerticalResolution);
       }
   }

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 isdisregarded. By setting this flag, users can specify whether the default colorprofile should be used instead of the embedded one. This option ensures greatercontrol over color management, facilitating adjustments for consistency andcompatibility 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 InterchangeFormat) data associated with the JPEG image. JFIF is a standard format forexchanging JPEG-compressed images between computers and other devices. By gettingor setting this property, you can interact with the JFIF data, which may includeinformation 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 thisAspose.Imaging.FileFormats.Jpeg.JpegImage instance with ease. This property offers valuable detailsabout the specific settings utilized, empowering users to understand and replicateimage processing workflows effectively. Whether it’s compression levels, qualitysettings, or other parameters, this property provides essential insights forseamless image manipulation.

public JpegOptions JpegOptionsget { get; }

Property Value

JpegOptions

Examples

The following example shows how to extract the header information from a JPEG image.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Jpeg.JpegImage image = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)Image.Load(dir + "original.jpg"))
   {
       Aspose.Imaging.ImageOptions.JpegOptions jpegOptions = image.JpegOptions;
       Console.WriteLine("The number of bits per channel: {0}", jpegOptions.BitsPerChannel);
       Console.WriteLine("The max allowed size for all internal buffers: {0}", jpegOptions.BufferSizeHint);
       Console.WriteLine("The color type: {0}", jpegOptions.ColorType);
       Console.WriteLine("The compression type: {0}", jpegOptions.CompressionType);
       Console.WriteLine("The image quality: {0}", jpegOptions.Quality);
       if (jpegOptions.ResolutionSettings != null)
       {
           Console.WriteLine("The horizontal resolution: {0}", jpegOptions.ResolutionSettings.HorizontalResolution);
           Console.WriteLine("The vertical resolution: {0}", jpegOptions.ResolutionSettings.VerticalResolution);
       }
       for (int i = 0; i < jpegOptions.HorizontalSampling.Length; i++)
       {
           Console.WriteLine("The sampling for component {0}: {1}x{2}", i, jpegOptions.HorizontalSampling[i], jpegOptions.VerticalSampling[i]);
       }
   }

RawDataFormat

This property retrieves the raw data format of the image, which indicates how theimage data is structured and encoded. Understanding the raw data format isessential for processing or manipulating the image data effectively. It providesinsights into the underlying representation of the image, such as whether it’scompressed, encoded in a specific color space, or stored in a particular fileformat. Accessing this property allows you to gain valuable information about theimage’s data structure, enabling you to perform various operations or optimizationstailored 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 colorconversion and representation. It must be paired with the CMYKColorProfile tomaintain consistency and fidelity in color rendering. This pairing is essential forapplications that require precise color management and reproduction of images,ensuring that the RGB data is properly interpreted and displayed.

public Stream SourceForRgbColorProfile {
    get {
        return this.RgbColorProfile;
    }
    set {
        this.RgbColorProfile = value;
    }
}

Property Value

StreamSource

Examples

The following example loads PNG and saves it to CMYK JPEG using custom ICC profile. Then loads CMYK JPEG and saves it back to PNG. The color conversion from RGB to CMYK and from CMYK to RGB is performed using custom ICC profiles.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Png.PngImage image = (Aspose.Imaging.FileFormats.Png.PngImage)Image.Load(dir + "sample.png"))
   {
       using (System.IO.Stream rgbProfileStream = System.IO.File.OpenRead(dir + "eciRGB_v2.icc"))
       using (System.IO.Stream cmykProfileStream = System.IO.File.OpenRead(dir + "ISOcoated_v2_FullGamut4.icc"))
       {
           Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
           saveOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.Cmyk;
           saveOptions.RgbColorProfile = new Aspose.Imaging.Sources.StreamSource(rgbProfileStream);
           saveOptions.CmykColorProfile = new Aspose.Imaging.Sources.StreamSource(cmykProfileStream);
           image.Save(dir + "output.cmyk.jpg", saveOptions);
       }
   }
   using (Aspose.Imaging.FileFormats.Jpeg.JpegImage image = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)Image.Load(dir + "output.cmyk.jpg"))
   {
       using (System.IO.Stream rgbProfileStream = System.IO.File.OpenRead(dir + "eciRGB_v2.icc"))
       using (System.IO.Stream cmykProfileStream = System.IO.File.OpenRead(dir + "ISOcoated_v2_FullGamut4.icc"))
       {
           image.RgbColorProfile = new Aspose.Imaging.Sources.StreamSource(rgbProfileStream);
           image.CmykColorProfile = new Aspose.Imaging.Sources.StreamSource(cmykProfileStream);
           Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
           image.Save(dir + "output.rgb.png", saveOptions);
       }
   }

VerticalResolution

This property manages the vertical resolution, expressed in pixels per inch, forthe associated Aspose.Imaging.RasterImage. Adjusting this resolution impacts thesize 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 packedvertically, affecting its overall sharpness and clarity.

public override double VerticalResolution
{
    get;
    set;
}

Property Value

double

Examples

The following example shows how to set horizontal/vertical resolution of a JPEG image.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
   {
       Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)image;
       double horizontalResolution = jpegImage.HorizontalResolution;
       double verticalResolution = jpegImage.VerticalResolution;
       System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
       System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
       if (horizontalResolution != 96.0 || verticalResolution != 96.0)
       {
           System.Console.WriteLine("Set resolution values to 96 dpi");
           jpegImage.SetResolution(96.0, 96.0);
           System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", jpegImage.HorizontalResolution);
           System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", jpegImage.VerticalResolution);
       }
   }

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 providesessential information about the image’s dimensions, enabling accurate rendering,manipulation, or display of the image data.

public override int Width
   {
      get;
   }

Property Value

int

XmpData

Gets or sets XMP metadata, enabling seamless integration ofdescriptive information into the image file. Whether you’re extracting existing XMPmetadata or updating it with new information, this property simplifies themanagement of extended metadata, ensuring compatibility with various applicationsand workflows.

public override XmpPacketWrapper XmpData
    {
        get;
        set;
    }

Property Value

XmpPacketWrapper

Methods

AutoRotate()

Automatically rotates the image based on orientation data extracted from Exifmetadata. This method ensures that images are displayed in the correct orientation,enhancing user experience and eliminating the need for manual adjustments. Byanalyzing Exif information, the image is rotated accordingly, providing a seamlessviewing experience across different platforms and devices. This automated rotationprocess simplifies image handling and improves overall usability, especially whendealing 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 latestmodification. This method provides valuable metadata, enabling users to track andmanage updates to the image file effectively. By accessing this information, userscan ensure the integrity and currency of their image assets, facilitating informeddecision-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.

GetOriginalOptions()

Gets the original image options of this Aspose.Imaging.Image instance.

public override ImageOptionsBase GetOriginalOptions()
{
}

Returns

ImageOptionsBase

A clone of original image options.

ReleaseManagedResources()

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

protected override void ReleaseManagedResources()
   {
      base.ReleaseManagedResources();
   }

RemoveMetadata()

Removes this image instance metadata by setting this Aspose.Imaging.Xmp.IHasXmpData.XmpData and Aspose.Imaging.Exif.IHasExifData.ExifData values to null.

public override void
      RemoveMetadata()
   {
   }

SaveData(Stream)

Saves the data.

protected override void SaveData(Stream stream)
   {
      base.SaveData(stream);
   }

Parameters

stream Stream

The stream to save data to.

SetResolution(double, double)

Establishes the resolution for the specified Aspose.Imaging.RasterImage, ensuringaccurate scaling and printing capabilities. This method empowers users to tailorthe image resolution to suit their specific requirements, whether for digitaldisplay or physical reproduction. By setting the resolution, users can optimizeimage 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 Aspose.Imaging.RasterImage.

dpiY double

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

Examples

The following example shows how to set horizontal/vertical resolution of a JPEG image.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
   {
       Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = (Aspose.Imaging.FileFormats.Jpeg.JpegImage)image;
       double horizontalResolution = jpegImage.HorizontalResolution;
       double verticalResolution = jpegImage.VerticalResolution;
       System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
       System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
       if (horizontalResolution != 96.0 || verticalResolution != 96.0)
       {
           System.Console.WriteLine("Set resolution values to 96 dpi");
           jpegImage.SetResolution(96.0, 96.0);
           System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", jpegImage.HorizontalResolution);
           System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", jpegImage.VerticalResolution);
       }
   }

UpdateDimensions(int, int)

Updates the image dimensions.

protected override void UpdateDimensions(
       int newWidth,
       int newHeight
   )
{
}

Parameters

newWidth int

The new image width.

newHeight int

The new image height.

UpdateMetadata()

Updates the image metadata.

protected override void UpdateMetadata()
   {
   }
 English