public final class JpegImage extends RasterCachedImage
A jpeg image.
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)
Initializes a new instance of the
JpegImage class. |
JpegImage(int width,
int height)
Initializes a new instance of the
JpegImage class. |
JpegImage(JpegOptions jpegOptions,
int width,
int height)
Initializes a new instance of the
JpegImage class. |
JpegImage(RasterImage rasterImage)
Initializes a new instance of the
JpegImage class. |
JpegImage(String path)
Initializes a new instance of the
JpegImage class. |
Modifier and Type | Method and Description |
---|---|
void |
autoRotate()
Perform automatic rotate of image depending on orientation data provided by Exif.
|
int |
getBitsPerPixel()
Gets the image bits per pixel count.
|
StreamSource |
getCmykColorProfile()
The CMYK color profile for CMYK and YCCK jpeg images.
|
String |
getComment()
Gets the jpeg file comment.
|
StreamSource |
getDestinationCmykColorProfile()
The CMYK color profile for CMYK and YCCK jpeg images, used for image saving process.
|
StreamSource |
getDestinationRgbColorProfile()
The RGB color profile for CMYK and YCCK jpeg images, used for image saving process.
|
JpegExifData |
getExifData()
Get or set exif data container
|
long |
getFileFormat()
Gets a value of file format
|
int |
getHeight()
Gets the image height.
|
double |
getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this
RasterImage . |
boolean |
getIgnoreEmbeddedColorProfile()
Gets a value indicating whether embedded color profile is ignored.
|
JFIFData |
getJfif()
Gets the jfif.
|
JpegOptions |
getJpegOptions()
Gets the JPEG options used to create or load this
JpegImage instance. |
PixelDataFormat |
getRawDataFormat()
Gets the raw data format.
|
StreamSource |
getRgbColorProfile()
The RGB color profile for CMYK and YCCK jpeg images.
|
double |
getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this
RasterImage . |
int |
getWidth()
Gets the image width.
|
XmpPacketWrapper |
getXmpData()
Gets the XMP metadata.
|
void |
setCmykColorProfile(StreamSource value)
The CMYK color profile for CMYK and YCCK jpeg images.
|
void |
setComment(String value)
Sets the jpeg file comment.
|
void |
setDestinationCmykColorProfile(StreamSource value)
The CMYK color profile for CMYK and YCCK jpeg images, used for image saving process.
|
void |
setDestinationRgbColorProfile(StreamSource value)
The RGB color profile for CMYK and YCCK jpeg images, used for image saving process.
|
void |
setExifData(JpegExifData value)
Get or set exif data container
|
void |
setHorizontalResolution(double value)
Sets the horizontal resolution, in pixels per inch, of this
RasterImage . |
void |
setIgnoreEmbeddedColorProfile(boolean value)
Sets a value indicating whether embedded color profile is ignored.
|
void |
setJfif(JFIFData value)
Sets the jfif.
|
void |
setResolution(double dpiX,
double dpiY)
Sets the resolution for this
RasterImage . |
void |
setRgbColorProfile(StreamSource value)
The RGB color profile for CMYK and YCCK jpeg images.
|
void |
setVerticalResolution(double value)
Sets the vertical resolution, in pixels per inch, of this
RasterImage . |
void |
setXmpData(XmpPacketWrapper value)
Sets the XMP metadata.
|
adjustBrightness, adjustContrast, adjustGamma, adjustGamma, binarizeBradley, binarizeBradley, binarizeFixed, binarizeOtsu, cacheData, crop, dither, grayscale, isCached, resize, resize, rotate, rotateFlip
crop, dither, filter, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getImageOpacity, getModifyDate, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, hasAlpha, hasTransparentColor, isRawDataAvailable, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, 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, writeScanLine
canLoad, canLoad, canLoad, canLoad, canSave, create, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getOriginalOptions, getPalette, getProgressEventHandler, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSize, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalette
getDataStreamContainer, save, save, save, save
close, dispose, getDisposed
public JpegImage(String path)
Initializes a new instance of the JpegImage
class.
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)
Initializes a new instance of the JpegImage
class.
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)
Initializes a new instance of the JpegImage
class.
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)
Initializes a new instance of the JpegImage
class.
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)
Initializes a new instance of the JpegImage
class.
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()
Gets a value of file format
getFileFormat
in class Image
public JpegOptions getJpegOptions()
Gets the JPEG options used to create or load this JpegImage
instance.
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()
Gets the image bits per pixel count.
getBitsPerPixel
in class Image
public String getComment()
Gets the jpeg file comment.
public void setComment(String value)
Sets the jpeg file comment.
public JpegExifData getExifData()
Get or set exif data container
The 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(JpegExifData value)
Get or set exif data container
public XmpPacketWrapper getXmpData()
Gets the XMP metadata.
getXmpData
in class RasterImage
public void setXmpData(XmpPacketWrapper value)
Sets the XMP metadata.
setXmpData
in class RasterImage
value
- The XMP metadata.public int getHeight()
Gets the image height.
getHeight
in interface IObjectWithBounds
getHeight
in class Image
public double getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this RasterImage
.
getHorizontalResolution
in class RasterImage
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.
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)
Sets the horizontal resolution, in pixels per inch, of this RasterImage
.
setHorizontalResolution
in class RasterImage
value
- 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()
Gets the jfif.
public void setJfif(JFIFData value)
Sets the jfif.
public PixelDataFormat getRawDataFormat()
Gets the raw data format.
getRawDataFormat
in class RasterImage
public double getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this RasterImage
.
getVerticalResolution
in class RasterImage
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.
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)
Sets the vertical resolution, in pixels per inch, of this RasterImage
.
setVerticalResolution
in class RasterImage
value
- 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()
Gets the image width.
getWidth
in interface IObjectWithBounds
getWidth
in class Image
public StreamSource getRgbColorProfile()
The RGB color profile for CMYK and YCCK jpeg images. Must be in pair with CMYKColorProfile for correct color conversion.
public void setRgbColorProfile(StreamSource value)
The RGB color profile for CMYK and YCCK jpeg images. Must be in pair with CMYKColorProfile for correct color conversion.
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 for CMYK and YCCK jpeg images. Must be in pair with RGBColorProfile for correct color conversion.
public void setCmykColorProfile(StreamSource value)
The CMYK color profile for CMYK and YCCK jpeg images. Must be in pair with RGBColorProfile for correct color conversion.
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 RGB color profile for CMYK and YCCK jpeg images, used for image saving process. Must be in pair with CMYKColorProfile for correct color conversion.
public void setDestinationRgbColorProfile(StreamSource value)
The RGB color profile for CMYK and YCCK jpeg images, used for image saving process. Must be in pair with CMYKColorProfile for correct color conversion.
public StreamSource getDestinationCmykColorProfile()
The CMYK color profile for CMYK and YCCK jpeg images, used for image saving process. Must be in pair with RGBColorProfile for correct color conversion.
public void setDestinationCmykColorProfile(StreamSource value)
The CMYK color profile for CMYK and YCCK jpeg images, used for image saving process. Must be in pair with RGBColorProfile for correct color conversion.
public boolean getIgnoreEmbeddedColorProfile()
Gets a value indicating whether embedded color profile is ignored. If embedded color profile is ignored, dafault color profile is used.
public void setIgnoreEmbeddedColorProfile(boolean value)
Sets a value indicating whether embedded color profile is ignored. If embedded color profile is ignored, dafault color profile is used.
public void setResolution(double dpiX, double dpiY)
Sets the resolution for this RasterImage
.
setResolution
in class RasterImage
dpiX
- 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()
Perform automatic rotate of image depending on orientation data provided by Exif.