Class JpegImage
Namespace: Aspose.Imaging.FileFormats.Jpeg
Assembly: Aspose.Imaging.dll (25.2.0)
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.
[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.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.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.```csharp [C#]
using (var image = (JpegImage)Image.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.```csharp
[C#]
string dir = "c:\\temp\\";
// Load a JPEG image from a file.
using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(dir + "sample.jpg"))
{
// Do some image processing.
// Save to another JPEG file.
jpegImage.Save(dir + "sample.output.jpg");
}
Constructors
JpegImage(string)
The Aspose.Imaging.FileFormats.Jpeg.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.
Examples
The example shows how to load a JpegImage from a file.```csharp [C#]
string dir = "c:\\temp\\";
// Load a JPEG image from a file.
using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(dir + "sample.jpg"))
{
// Do some image processing.
// Save to another JPEG file.
jpegImage.Save(dir + "sample.output.jpg");
}
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage__ctor_System_IO_Stream_"></a> JpegImage\(Stream\)
Initialize a JPEG image object with the Aspose.Imaging.FileFormats.Jpeg.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.
```csharp
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.```csharp [C#]
string dir = "c:\\temp\\";
// Load a JPEG image from a file stream.
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))
{
// Do some image processing.
// Save to another JPEG file.
jpegImage.Save(dir + "sample.output.jpg");
}
}
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage__ctor_Aspose_Imaging_RasterImage_"></a> JpegImage\(RasterImage\)
Initialize a new instance of the Aspose.Imaging.FileFormats.Jpeg.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.
```csharp
public JpegImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImage
The image to initialize pixel and palette data with.
Examples
The example shows how to load a JpegImage from another RasterImage.```csharp [C#]
string dir = "c:\\temp\\";
// Load a JPEG image from another raster image.
// First, create a temporal PNG image that will be a foundation for building a JPEG image.
// You can also load PNG image from a file or use an image of any other raster format.
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))
{
// Fill the entire PNG image in red.
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);
// Create a JPEG image based on the PNG image.
using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(rasterImage))
{
// Save to a JPEG file
jpegImage.Save(dir + "output.jpg");
}
}
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage__ctor_System_Int32_System_Int32_"></a> JpegImage\(int, int\)
Create a new instance of the Aspose.Imaging.FileFormats.Jpeg.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.
```csharp
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.```csharp [C#]
string dir = "c:\\temp\\";
// Create a JPEG image of 100x100 px.
using (Aspose.Imaging.FileFormats.Jpeg.JpegImage jpegImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(100, 100))
{
// Do some image processing.
// Save to a file.
jpegImage.Save(dir + "output.jpg");
}
The following example loads a BMP image and saves it to JPEG using various save options.```csharp
[C#]
string dir = "c:\\temp\\";
// Load a BMP image from a file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
// Do some image processing.
// Use additional options to specify the desired image parameters.
Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
// The number of bits per channel is 8.
// When a palette is used, the color index is stored in the image data instead of the color itself.
saveOptions.BitsPerChannel = 8;
// Set the progressive type of compression.
saveOptions.CompressionType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionMode.Progressive;
// Set the image quality. It is a value between 1 and 100.
saveOptions.Quality = 100;
// Set the horizontal/vertical resolution to 96 dots per inch.
saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
saveOptions.ResolutionUnit = Aspose.Imaging.ResolutionUnit.Inch;
// If the source image is colored, it will be converted to grayscaled.
saveOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.Grayscale;
// Use a palette to reduce the output size.
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, 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.
Examples
The following example loads a BMP image and saves it to JPEG using various save options.```csharp [C#]
string dir = "c:\\temp\\";
// Load a BMP image from a file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
// Do some image processing.
// Use additional options to specify the desired image parameters.
Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
// The number of bits per channel is 8.
// When a palette is used, the color index is stored in the image data instead of the color itself.
saveOptions.BitsPerChannel = 8;
// Set the progressive type of compression.
saveOptions.CompressionType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionMode.Progressive;
// Set the image quality. It is a value between 1 and 100.
saveOptions.Quality = 100;
// Set the horizontal/vertical resolution to 96 dots per inch.
saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
saveOptions.ResolutionUnit = Aspose.Imaging.ResolutionUnit.Inch;
// If the source image is colored, it will be converted to grayscaled.
saveOptions.ColorType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionColorMode.Grayscale;
// Use a palette to reduce the output size.
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.```csharp
[C#]
string dir = "c:\\temp\\";
// Create a JPEG image of 100x100 px.
// Use additional options to specify the desired image parameters.
Aspose.Imaging.ImageOptions.JpegOptions createOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
// The number of bits per channel is 8, 8, 8 for Y, Cr, Cb components accordingly.
createOptions.BitsPerChannel = 8;
// Set the progressive type of compression.
createOptions.CompressionType = Aspose.Imaging.FileFormats.Jpeg.JpegCompressionMode.Progressive;
// Set the image quality. It is a value between 1 and 100.
createOptions.Quality = 100;
// Set the horizontal/vertical resolution to 96 dots per inch.
createOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
createOptions.ResolutionUnit = Aspose.Imaging.ResolutionUnit.Inch;
// This is a standard option for JPEG images.
// Two chroma components (Cb and Cr) can be bandwidth-reduced, subsampled, compressed.
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);
// Fill the image with a grayscale gradient
graphics.FillRectangle(gradientBrush, jpegImage.Bounds);
// Save to a file.
jpegImage.Save(dir + "output.explicitoptions.jpg");
}
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
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
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.```csharp [C#]
string dir = "c:\\temp\\";
// Load PNG and save it to CMYK JPEG
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;
// Use custom ICC profiles
saveOptions.RgbColorProfile = new Aspose.Imaging.Sources.StreamSource(rgbProfileStream);
saveOptions.CmykColorProfile = new Aspose.Imaging.Sources.StreamSource(cmykProfileStream);
image.Save(dir + "output.cmyk.jpg", saveOptions);
}
}
// Load CMYK JPEG and save it to PNG
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"))
{
// Use custom ICC profiles
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);
}
}
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_Comment"></a> 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.
```csharp
public string Comment { get; set; }
Property Value
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
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
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
Examples
The following example shows how to extract EXIF tags from a JPEG image.```csharp [C#]
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("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);
}
}
//The output looks like this:
//The general EXIF data
//------------------------------------------
//The EXIF version: System.Byte[]
//The camera serial number: 7100536
//The color space: SRgb
//The brightness:
//The contrast: Normal
//The gamma:
//The sharpness: 0
//The aperture: 4.64(4643856 / 1000000)
//The exposure mode: Manual
//The exposure bias: 0.67(4 / 6)
//The exposure time: 0.01(1 / 160)
//The focal length: 145.00(1450 / 10)
//The focal plane resolution unit: Cm
//The lens model: 70.0 - 200.0 mm f/ 4.0
//The shutter speed: 7.32(7321928 / 1000000)
//The JPEG EXIF data
//------------------------------------------
//The camera manufacturer: NIKON CORPORATION
//The camera model: NIKON D5
//The photometric interpretation: 0
//The artist:
//The copyright:
//The image description:
//The orientation: TopLeft
//The software: Adobe Photoshop Camera Raw 9.9(Macintosh)
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_FileFormat"></a> 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.
```csharp
public override FileFormat FileFormat { get; }
Property Value
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
HorizontalResolution
This property grants you access to the horizontal resolution of the Aspose.Imaging.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
Examples
The following example shows how to set horizontal/vertical resolution of a JPEG image.```csharp [C#]
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;
// Get horizontal and vertical resolution of the BmpImage
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)
{
// Use the SetResolution method for updating both resolution values in a single call.
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);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300
// The vertical resolution, in pixels per inch: 300
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96
// The vertical resolution, in pixels per inch: 96
}
#### 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.
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_IgnoreEmbeddedColorProfile"></a> 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.
```csharp
public bool IgnoreEmbeddedColorProfile { get; set; }
Property Value
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
JpegOptions
Gain access to the JPEG options employed during the creation or loading of this Aspose.Imaging.FileFormats.Jpeg.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
Examples
The following example shows how to extract the header information from a JPEG image.```csharp [C#]
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;
System.Console.WriteLine("The number of bits per channel: {0}", jpegOptions.BitsPerChannel);
System.Console.WriteLine("The max allowed size for all internal buffers: {0}", jpegOptions.BufferSizeHint);
System.Console.WriteLine("The color type: {0}", jpegOptions.ColorType);
System.Console.WriteLine("The compression type: {0}", jpegOptions.CompressionType);
System.Console.WriteLine("The image quality: {0}", jpegOptions.Quality);
if (jpegOptions.ResolutionSettings != null)
{
System.Console.WriteLine("The horizontal resolution: {0}", jpegOptions.ResolutionSettings.HorizontalResolution);
System.Console.WriteLine("The vertical resolution: {0}", jpegOptions.ResolutionSettings.VerticalResolution);
}
for (int i = 0; i < jpegOptions.HorizontalSampling.Length; i++)
{
System.Console.WriteLine("The sampling for component {0}: {1}x{2}", i, jpegOptions.HorizontalSampling[i], jpegOptions.VerticalSampling[i]);
}
}
//The output looks like this:
//The number of bits per channel: 8
//The max allowed size for all internal buffers: 0
//The color type: YCbCr
//The compression type: Baseline
//The image quality: 75
//The sampling for component 0: 1x1
//The sampling for component 1: 1x1
//The sampling for component 2: 1x1
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_RawDataFormat"></a> 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.
```csharp
public override PixelDataFormat RawDataFormat { get; }
Property Value
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
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.```csharp [C#]
string dir = "c:\\temp\\";
// Load PNG and save it to CMYK JPEG
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;
// Use custom ICC profiles
saveOptions.RgbColorProfile = new Aspose.Imaging.Sources.StreamSource(rgbProfileStream);
saveOptions.CmykColorProfile = new Aspose.Imaging.Sources.StreamSource(cmykProfileStream);
image.Save(dir + "output.cmyk.jpg", saveOptions);
}
}
// Load CMYK JPEG and save it to PNG
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"))
{
// Use custom ICC profiles
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);
}
}
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_VerticalResolution"></a> VerticalResolution
This property manages the vertical resolution, expressed in pixels per inch, for
the associated Aspose.Imaging.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.
```csharp
public override double VerticalResolution { get; set; }
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a JPEG image.```csharp [C#]
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;
// Get horizontal and vertical resolution of the BmpImage
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)
{
// Use the SetResolution method for updating both resolution values in a single call.
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);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300
// The vertical resolution, in pixels per inch: 300
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96
// The vertical resolution, in pixels per inch: 96
}
#### 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.
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_Width"></a> 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.
```csharp
public override int Width { get; }
Property Value
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
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
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
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 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)
Parameters
stream
Stream
The stream to save data to.
SetResolution(double, double)
Establishes the resolution for the specified Aspose.Imaging.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 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.```csharp [C#]
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;
// Get horizontal and vertical resolution of the BmpImage
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)
{
// Use the SetResolution method for updating both resolution values in a single call.
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);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300
// The vertical resolution, in pixels per inch: 300
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96
// The vertical resolution, in pixels per inch: 96
}
### <a id="Aspose_Imaging_FileFormats_Jpeg_JpegImage_UpdateDimensions_System_Int32_System_Int32_"></a> UpdateDimensions\(int, int\)
Updates the image dimensions.
```csharp
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()