public final class JpegImage extends RasterCachedImage implements com.aspose.internal.IMetadataContainer, IHasJpegExifData
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.
The example shows how to load a JpegImage from a file.
String dir = "c:\\temp\\";
// Load a JPEG image from a file.
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = new com.aspose.imaging.fileformats.jpeg.JpegImage(dir + "sample.jpg");
try {
// Do some image processing.
// Save to another JPEG file.
jpegImage.save(dir + "sample.output.jpg");
} finally {
jpegImage.dispose();
}
| Constructor and Description |
|---|
JpegImage(InputStream stream)
Initialize a JPEG image object with the
JpegImage class using a
stream parameter. |
JpegImage(int width,
int height)
Create a new instance of the
JpegImage class with the specified width
and height parameters. |
JpegImage(JpegOptions jpegOptions,
int width,
int height)
Initialize a new
JpegImage object with the provided JPEG options. |
JpegImage(RasterImage rasterImage)
Initialize a new instance of the
JpegImage class with a raster image
parameter. |
JpegImage(String path)
The
JpegImage class initiates effortlessly by invoking its
constructor with the specified path parameter. |
| Modifier and Type | Method and Description |
|---|---|
void |
autoRotate()
Automatically rotates the image based on orientation data extracted from Exif
metadata.
|
int |
getBitsPerPixel()
Retrieve the pixel depth of the image effortlessly with this property, offering
insights into the richness of color or grayscale representation.
|
StreamSource |
getCmykColorProfile()
The CMYK color profile associated with CMYK and YCCK JPEG images ensures precise
color conversion and fidelity.
|
String |
getComment()
Manage JPEG file comments with this property, allowing you to add or retrieve
descriptive annotations associated with the image.
|
StreamSource |
getDestinationCmykColorProfile()
The CMYK color profile is vital for the accurate color conversion of CMYK and YCCK
JPEG images during the saving process.
|
StreamSource |
getDestinationRgbColorProfile()
The RGBColorProfile is essential for the accurate color conversion of CMYK and YCCK
JPEG images during the saving process.
|
ExifData |
getExifData()
Gets Exif data;
|
long |
getFileFormat()
Retrieve the format of the image effortlessly with this property.
|
int |
getHeight()
Retrieve the height of the image effortlessly with this property.
|
double |
getHorizontalResolution()
This property grants you access to the horizontal resolution of the
RasterImage, measured in pixels per inch. |
boolean |
getIgnoreEmbeddedColorProfile()
Retrieves or modifies the flag denoting whether the embedded color profile is
disregarded.
|
JFIFData |
getJfif()
This property allows you to access or modify the JFIF (JPEG File Interchange
Format) data associated with the JPEG image.
|
JpegExifData |
getJpegExifData()
Gets Exif instance.
|
JpegOptions |
getJpegOptions()
Gain access to the JPEG options employed during the creation or loading of this
JpegImage instance with ease. |
ImageOptionsBase |
getOriginalOptions()
Gets the original image options of this
Image instance. |
PixelDataFormat |
getRawDataFormat()
This property retrieves the raw data format of the image, which indicates how the
image data is structured and encoded.
|
StreamSource |
getRgbColorProfile()
The RGB color profile for CMYK and YCCK JPEG images ensures accurate color
conversion and representation.
|
double |
getVerticalResolution()
This property manages the vertical resolution, expressed in pixels per inch, for
the associated
RasterImage. |
int |
getWidth()
This property retrieves the width of the image, expressed in pixels.
|
XmpPacketWrapper |
getXmpData()
Handle XMP metadata with this property, enabling seamless integration of
descriptive information into the image file.
|
void |
removeMetadata()
Removes this image instance metadata by setting this
IHasXmpData.XmpData(IHasXmpData.getXmpData()/IHasXmpData.setXmpData(XmpPacketWrapper))
and IHasExifData.ExifData(IHasExifData.getExifData()/IHasExifData.setExifData(ExifData)) values to null. |
void |
setCmykColorProfile(StreamSource value)
The CMYK color profile associated with CMYK and YCCK JPEG images ensures precise
color conversion and fidelity.
|
void |
setComment(String value)
Manage JPEG file comments with this property, allowing you to add or retrieve
descriptive annotations associated with the image.
|
void |
setDestinationCmykColorProfile(StreamSource value)
The CMYK color profile is vital for the accurate color conversion of CMYK and YCCK
JPEG images during the saving process.
|
void |
setDestinationRgbColorProfile(StreamSource value)
The RGBColorProfile is essential for the accurate color conversion of CMYK and YCCK
JPEG images during the saving process.
|
void |
setExifData(ExifData value)
Sets Exif data;
|
void |
setHorizontalResolution(double value)
This property grants you access to the horizontal resolution of the
RasterImage, measured in pixels per inch. |
void |
setIgnoreEmbeddedColorProfile(boolean value)
Retrieves or modifies the flag denoting whether the embedded color profile is
disregarded.
|
void |
setJfif(JFIFData value)
This property allows you to access or modify the JFIF (JPEG File Interchange
Format) data associated with the JPEG image.
|
void |
setJpegExifData(JpegExifData value)
Manage EXIF data with this property, allowing you to add or retrieve metadata
associated with the image.
|
void |
setResolution(double dpiX,
double dpiY)
Establishes the resolution for the specified
RasterImage, ensuring
accurate scaling and printing capabilities. |
void |
setRgbColorProfile(StreamSource value)
The RGB color profile for CMYK and YCCK JPEG images ensures accurate color
conversion and representation.
|
void |
setVerticalResolution(double value)
This property manages the vertical resolution, expressed in pixels per inch, for
the associated
RasterImage. |
void |
setXmpData(XmpPacketWrapper value)
Sets XMP metadata, enabling seamless integration of
descriptive information into the image file.
|
adjustBrightness, adjustContrast, adjustGamma, adjustGamma, analyzePercentageDigitalSignature, autoBrightnessContrast, binarizeBradley, binarizeBradley, binarizeFixed, binarizeOtsu, blend, cacheData, crop, dither, embedDigitalSignature, grayscale, isCached, isDigitalSigned, normalizeHistogram, resize, resize, rotate, rotateFlipblend, blend, blend, dither, filter, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getImageOpacity, getModifyDate, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, hasAlpha, hasTransparentColor, isDigitalSigned, isRawDataAvailable, isUsePalette, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialArgb64Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, normalizeAngle, readArgb32ScanLine, readScanLine, replaceColor, replaceColor, replaceNonTransparentColors, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setPalette, setPixel, setPremultiplyComponents, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setTransparentColor, setTransparentColor, setUpdateXmpData, setUseRawData, toBitmap, writeArgb32ScanLine, writeScanLinecanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, create, create, create, crop, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getIProgressEventHandler, getPalette, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSerializedStream, getSize, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalettegetDataStreamContainer, save, save, saveclose, dispose, getDisposedpublic JpegImage(String path)
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.
path - The path to load image from and initialize pixel and palette data with.The example shows how to load a JpegImage from a file.
String dir = "c:\\temp\\";
// Load a JPEG image from a file.
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = new com.aspose.imaging.fileformats.jpeg.JpegImage(dir + "sample.jpg");
try {
// Do some image processing.
// Save to another JPEG file.
jpegImage.save(dir + "sample.output.jpg");
} finally {
jpegImage.dispose();
}
public JpegImage(InputStream 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.
stream - The stream to load image from and initialize pixel and palette data with.The example shows how to load a JpegImage from a file stream.
String dir = "c:\\temp\\";
// Load a JPEG image from a file stream.
java.io.InputStream stream = new java.io.FileInputStream(dir + "sample.jpg");
try {
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = new com.aspose.imaging.fileformats.jpeg.JpegImage(stream);
try {
// Do some image processing.
// Save to another JPEG file.
jpegImage.save(dir + "sample.output.jpg");
} finally {
jpegImage.dispose();
}
} finally {
stream.close();
}
public JpegImage(RasterImage 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.
rasterImage - The image to initialize pixel and palette data with.The example shows how to load a JpegImage from another RasterImage.
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.
com.aspose.imaging.imageoptions.PngOptions createOptions = new com.aspose.imaging.imageoptions.PngOptions();
createOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]), false));
com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(createOptions, 100, 100);
try {
// Fill the entire PNG image in red.
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(rasterImage);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
graphics.fillRectangle(brush, rasterImage.getBounds());
// Create a JPEG image based on the PNG image.
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = new com.aspose.imaging.fileformats.jpeg.JpegImage(rasterImage);
try {
// Save to a JPEG file
jpegImage.save(dir + "output.jpg");
} finally {
jpegImage.dispose();
}
} finally {
rasterImage.dispose();
}
public JpegImage(int width,
int height)
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.
width - The image width.height - The image height.The following example shows how to create JPEG image of the specified size.
String dir = "c:\\temp\\";
// Create a JPEG image of 100x100 px.
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = new com.aspose.imaging.fileformats.jpeg.JpegImage(100, 100);
try {
// Do some image processing.
// Save to a file.
jpegImage.save(dir + "output.jpg");
} finally {
jpegImage.dispose();
}
public JpegImage(JpegOptions jpegOptions, int width, int height)
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.
jpegOptions - The jpeg options.width - Image width.height - Image height.The following example shows how to create JPEG image of the specified size with the specified parameters.
String dir = "c:\\temp\\";
// Create a JPEG image of 100x100 px.
// Use additional options to specify the desired image parameters.
com.aspose.imaging.imageoptions.JpegOptions createOptions = new com.aspose.imaging.imageoptions.JpegOptions();
// The number of bits per channel is 8, 8, 8 for Y, Cr, Cb components accordingly.
createOptions.setBitsPerChannel((byte) 8);
// Set the progressive type of compression.
createOptions.setCompressionType(com.aspose.imaging.fileformats.jpeg.JpegCompressionMode.Progressive);
// Set the image quality. It is a value between 1 and 100.
createOptions.setQuality(100);
// Set the horizontal/vertical resolution to 96 dots per inch.
createOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));
createOptions.setResolutionUnit(com.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.setColorType(com.aspose.imaging.fileformats.jpeg.JpegCompressionColorMode.YCbCr);
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = new com.aspose.imaging.fileformats.jpeg.JpegImage(createOptions, 100, 100);
try {
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(jpegImage);
com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
new com.aspose.imaging.Point(0, 0),
new com.aspose.imaging.Point(jpegImage.getWidth(), jpegImage.getHeight()),
com.aspose.imaging.Color.getYellow(),
com.aspose.imaging.Color.getBlue());
// Fill the image with a grayscale gradient
graphics.fillRectangle(gradientBrush, jpegImage.getBounds());
// Save to a file.
jpegImage.save(dir + "output.explicitoptions.jpg");
} finally {
jpegImage.dispose();
}
public long getFileFormat()
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.
getFileFormat in class ImageFileFormatpublic JpegOptions getJpegOptions()
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.
The following example shows how to extract the header information from a JPEG image.
String dir = "c:\\temp\\";
com.aspose.imaging.fileformats.jpeg.JpegImage image = (com.aspose.imaging.fileformats.jpeg.JpegImage) com.aspose.imaging.Image.load(dir + "original.jpg");
try {
com.aspose.imaging.imageoptions.JpegOptions jpegOptions = image.getJpegOptions();
System.out.println("The number of bits per channel: " + jpegOptions.getBitsPerChannel());
System.out.println("The max allowed size for all internal buffers: " + jpegOptions.getBufferSizeHint());
System.out.println("The color type: " + jpegOptions.getColorType());
System.out.println("The compression type: " + jpegOptions.getCompressionType());
System.out.println("The image quality: " + jpegOptions.getQuality());
if (jpegOptions.getResolutionSettings() != null) {
System.out.println("The horizontal resolution: " + jpegOptions.getResolutionSettings().getHorizontalResolution());
System.out.println("The vertical resolution: " + jpegOptions.getResolutionSettings().getVerticalResolution());
}
for (int i = 0; i < jpegOptions.getHorizontalSampling().length; i++) {
System.out.printf("The sampling for component %s: %sx%s\r\n", i, jpegOptions.getHorizontalSampling()[i], jpegOptions.getVerticalSampling()[i]);
}
} finally {
image.dispose();
}
//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
public int getBitsPerPixel()
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.
getBitsPerPixel in class Imagepublic String getComment()
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 void setComment(String value)
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 JpegExifData getJpegExifData()
Gets Exif instance.
getJpegExifData in interface IHasJpegExifDatapublic void setJpegExifData(JpegExifData value)
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.
setJpegExifData in interface IHasJpegExifDatavalue - Exif instance.public XmpPacketWrapper getXmpData()
Handle XMP metadata with this property, 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.
getXmpData in interface IHasXmpDatagetXmpData in class RasterImagepublic void setXmpData(XmpPacketWrapper value)
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.
setXmpData in interface IHasXmpDatasetXmpData in class RasterImagevalue - XMP metadata, enabling seamless integration of
descriptive information into the image file.public ExifData getExifData()
Gets Exif data;
getExifData in interface IHasExifDataThe following example shows how to extract EXIF tags from a JPEG image.
String dir = "c:\\temp\\";
com.aspose.imaging.fileformats.jpeg.JpegImage image = (com.aspose.imaging.fileformats.jpeg.JpegImage) com.aspose.imaging.Image.load(dir + "original.jpg");
try {
com.aspose.imaging.exif.ExifData exifData = image.getExifData();
System.out.println("The general EXIF data");
System.out.println("------------------------------------------");
if (exifData != null) {
System.out.println("The EXIF version: " + exifData.getExifVersion());
System.out.println("The camera serial number: " + exifData.getBodySerialNumber());
System.out.println("The color space: " + exifData.getColorSpace());
System.out.println("The brightness: " + exifData.getBrightnessValue());
System.out.println("The contrast: " + exifData.getContrast());
System.out.println("The gamma: " + exifData.getGamma());
System.out.println("The sharpness: " + exifData.getSharpness());
System.out.println("The aperture: " + exifData.getApertureValue());
System.out.println("The exposure mode: " + exifData.getExposureMode());
System.out.println("The exposure bias: " + exifData.getExposureBiasValue());
System.out.println("The exposure time: " + exifData.getExposureTime());
System.out.println("The focal length: " + exifData.getFocalLength());
System.out.println("The focal plane resolution unit: " + exifData.getFocalPlaneResolutionUnit());
System.out.println("The lens model: " + exifData.getLensModel());
System.out.println("The shutter speed: " + exifData.getShutterSpeedValue());
}
System.out.println("The JPEG EXIF data");
System.out.println("------------------------------------------");
if (exifData instanceof com.aspose.imaging.exif.JpegExifData) {
com.aspose.imaging.exif.JpegExifData jpegExifData = (com.aspose.imaging.exif.JpegExifData) exifData;
System.out.println("The camera manufacturer: " + jpegExifData.getMake());
System.out.println("The camera model: " + jpegExifData.getModel());
System.out.println("The photometric interpretation: " + jpegExifData.getPhotometricInterpretation());
System.out.println("The artist: " + jpegExifData.getArtist());
System.out.println("The copyright: " + jpegExifData.getCopyright());
System.out.println("The image description: " + jpegExifData.getImageDescription());
System.out.println("The orientation: " + jpegExifData.getOrientation());
System.out.println("The software: " + jpegExifData.getSoftware());
}
} finally {
image.dispose();
}
//The output looks like this:
//The general EXIF data
//------------------------------------------
//The EXIF version: [B@163e4e87
//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)
public void setExifData(ExifData value)
Sets Exif data;
setExifData in interface IHasExifDatavalue - Exif data;public int getHeight()
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.
getHeight in interface IObjectWithBoundsgetHeight in class Imagepublic double getHorizontalResolution()
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.
getHorizontalResolution in class RasterImageNote 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.
The following example shows how to set horizontal/vertical resolution of a JPEG image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jpg");
try {
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = (com.aspose.imaging.fileformats.jpeg.JpegImage) image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = jpegImage.getHorizontalResolution();
double verticalResolution = jpegImage.getVerticalResolution();
System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
// Use the SetResolution method for updating both resolution values in a single call.
System.out.println("Set resolution values to 96 dpi");
jpegImage.setResolution(96.0, 96.0);
System.out.println("The horizontal resolution, in pixels per inch: " + jpegImage.getHorizontalResolution());
System.out.println("The vertical resolution, in pixels per inch: " + jpegImage.getVerticalResolution());
}
} finally {
image.dispose();
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300.0
// The vertical resolution, in pixels per inch: 300.0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.0
// The vertical resolution, in pixels per inch: 96.0
public void setHorizontalResolution(double value)
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.
setHorizontalResolution in class RasterImagevalue - The horizontal resolution.
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.
public JFIFData getJfif()
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 void setJfif(JFIFData value)
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 PixelDataFormat getRawDataFormat()
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.
getRawDataFormat in class RasterImagepublic double getVerticalResolution()
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.
getVerticalResolution in class RasterImageNote 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.
The following example shows how to set horizontal/vertical resolution of a JPEG image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jpg");
try {
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = (com.aspose.imaging.fileformats.jpeg.JpegImage) image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = jpegImage.getHorizontalResolution();
double verticalResolution = jpegImage.getVerticalResolution();
System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
// Use the SetResolution method for updating both resolution values in a single call.
System.out.println("Set resolution values to 96 dpi");
jpegImage.setResolution(96.0, 96.0);
System.out.println("The horizontal resolution, in pixels per inch: " + jpegImage.getHorizontalResolution());
System.out.println("The vertical resolution, in pixels per inch: " + jpegImage.getVerticalResolution());
}
} finally {
image.dispose();
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300.0
// The vertical resolution, in pixels per inch: 300.0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.0
// The vertical resolution, in pixels per inch: 96.0
public void setVerticalResolution(double value)
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.
setVerticalResolution in class RasterImagevalue - The vertical resolution.
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.
public int getWidth()
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.
getWidth in interface IObjectWithBoundsgetWidth in class Imagepublic StreamSource getRgbColorProfile()
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 void setRgbColorProfile(StreamSource value)
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.
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\\";
// Load PNG and save it to CMYK JPEG
com.aspose.imaging.fileformats.png.PngImage image = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.load(dir + "sample.png");
try {
java.io.InputStream rgbProfileStream = new java.io.FileInputStream(dir + "eciRGB_v2.icc");
java.io.InputStream cmykProfileStream = new java.io.FileInputStream(dir + "ISOcoated_v2_FullGamut4.icc");
try {
com.aspose.imaging.imageoptions.JpegOptions saveOptions = new com.aspose.imaging.imageoptions.JpegOptions();
saveOptions.setColorType(com.aspose.imaging.fileformats.jpeg.JpegCompressionColorMode.Cmyk);
// Use custom ICC profiles
saveOptions.setRgbColorProfile(new com.aspose.imaging.sources.StreamSource(rgbProfileStream));
saveOptions.setCmykColorProfile(new com.aspose.imaging.sources.StreamSource(cmykProfileStream));
image.save(dir + "output.cmyk.jpg", saveOptions);
} finally {
rgbProfileStream.close();
cmykProfileStream.close();
}
} finally {
image.dispose();
}
// Load CMYK JPEG and save it to PNG
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = (com.aspose.imaging.fileformats.jpeg.JpegImage) com.aspose.imaging.Image.load(dir + "output.cmyk.jpg");
try {
java.io.InputStream rgbProfileStream = new java.io.FileInputStream(dir + "eciRGB_v2.icc");
java.io.InputStream cmykProfileStream = new java.io.FileInputStream(dir + "ISOcoated_v2_FullGamut4.icc");
try {
// Use custom ICC profiles
jpegImage.setRgbColorProfile(new com.aspose.imaging.sources.StreamSource(rgbProfileStream));
jpegImage.setCmykColorProfile(new com.aspose.imaging.sources.StreamSource(cmykProfileStream));
com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
jpegImage.save(dir + "output.rgb.png", saveOptions);
} finally {
rgbProfileStream.close();
cmykProfileStream.close();
}
} finally {
jpegImage.dispose();
}
public StreamSource getCmykColorProfile()
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 void setCmykColorProfile(StreamSource value)
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.
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\\";
// Load PNG and save it to CMYK JPEG
com.aspose.imaging.fileformats.png.PngImage image = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.load(dir + "sample.png");
try {
java.io.InputStream rgbProfileStream = new java.io.FileInputStream(dir + "eciRGB_v2.icc");
java.io.InputStream cmykProfileStream = new java.io.FileInputStream(dir + "ISOcoated_v2_FullGamut4.icc");
try {
com.aspose.imaging.imageoptions.JpegOptions saveOptions = new com.aspose.imaging.imageoptions.JpegOptions();
saveOptions.setColorType(com.aspose.imaging.fileformats.jpeg.JpegCompressionColorMode.Cmyk);
// Use custom ICC profiles
saveOptions.setRgbColorProfile(new com.aspose.imaging.sources.StreamSource(rgbProfileStream));
saveOptions.setCmykColorProfile(new com.aspose.imaging.sources.StreamSource(cmykProfileStream));
image.save(dir + "output.cmyk.jpg", saveOptions);
} finally {
rgbProfileStream.close();
cmykProfileStream.close();
}
} finally {
image.dispose();
}
// Load CMYK JPEG and save it to PNG
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = (com.aspose.imaging.fileformats.jpeg.JpegImage) com.aspose.imaging.Image.load(dir + "output.cmyk.jpg");
try {
java.io.InputStream rgbProfileStream = new java.io.FileInputStream(dir + "eciRGB_v2.icc");
java.io.InputStream cmykProfileStream = new java.io.FileInputStream(dir + "ISOcoated_v2_FullGamut4.icc");
try {
// Use custom ICC profiles
jpegImage.setRgbColorProfile(new com.aspose.imaging.sources.StreamSource(rgbProfileStream));
jpegImage.setCmykColorProfile(new com.aspose.imaging.sources.StreamSource(cmykProfileStream));
com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
jpegImage.save(dir + "output.rgb.png", saveOptions);
} finally {
rgbProfileStream.close();
cmykProfileStream.close();
}
} finally {
jpegImage.dispose();
}
public StreamSource getDestinationRgbColorProfile()
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 void setDestinationRgbColorProfile(StreamSource value)
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 getDestinationCmykColorProfile()
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 void setDestinationCmykColorProfile(StreamSource value)
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 boolean getIgnoreEmbeddedColorProfile()
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 void setIgnoreEmbeddedColorProfile(boolean value)
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 ImageOptionsBase getOriginalOptions()
Gets the original image options of this Image instance.
getOriginalOptions in class Imagepublic void removeMetadata()
Removes this image instance metadata by setting this
IHasXmpData.XmpData(IHasXmpData.getXmpData()/IHasXmpData.setXmpData(XmpPacketWrapper))
and IHasExifData.ExifData(IHasExifData.getExifData()/IHasExifData.setExifData(ExifData)) values to null.
removeMetadata in class RasterImagepublic void setResolution(double dpiX,
double dpiY)
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.
setResolution in class RasterImagedpiX - The horizontal resolution, in dots per inch, of the RasterImage.dpiY - The vertical resolution, in dots per inch, of the RasterImage.The following example shows how to set horizontal/vertical resolution of a JPEG image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jpg");
try {
com.aspose.imaging.fileformats.jpeg.JpegImage jpegImage = (com.aspose.imaging.fileformats.jpeg.JpegImage) image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = jpegImage.getHorizontalResolution();
double verticalResolution = jpegImage.getVerticalResolution();
System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
// Use the SetResolution method for updating both resolution values in a single call.
System.out.println("Set resolution values to 96 dpi");
jpegImage.setResolution(96.0, 96.0);
System.out.println("The horizontal resolution, in pixels per inch: " + jpegImage.getHorizontalResolution());
System.out.println("The vertical resolution, in pixels per inch: " + jpegImage.getVerticalResolution());
}
} finally {
image.dispose();
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300.0
// The vertical resolution, in pixels per inch: 300.0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.0
// The vertical resolution, in pixels per inch: 96.0
public void 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.
com.aspose.ms.System.ArgumentOutOfRangeException - The 'Orientation' value of 'JpegExifData' is out of allowed range [1...8], so autorotation can not be applied.Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.