JpegOptions

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.ImageOptionsBase

public class JpegOptions extends ImageOptionsBase

Create high-quality JPEG images effortlessly with our API, offering adjustable levels of compression to optimize storage size without compromising image quality. Benefit from support for various compression types, near lossless coding, RGB and CMYK color profiles, as well as EXIF, JFIF image data, and XMP containers, ensuring versatile and customizable options for your image creation needs.

Constructors

ConstructorDescription
JpegOptions()Initializes a new instance of the JpegOptions class.
JpegOptions(JpegOptions jpegOptions)Initializes a new instance of the JpegOptions class.

Methods

MethodDescription
getDefaultMemoryAllocationLimit()Gets the default memory allocation limit.
setDefaultMemoryAllocationLimit(int value)Sets the default memory allocation limit.
getXmpData()Gets the XMP metadata container.
setXmpData(XmpPacketWrapper value)Sets the XMP metadata container.
getJfif()Gets the jfif.
setJfif(JFIFData value)Sets the jfif.
getComment()Gets the jpeg file comment.
setComment(String value)Sets the jpeg file comment.
getExifData()Get or set exif data container
setExifData(JpegExifData value)Get or set exif data container
getCompressionType()Gets the compression type.
setCompressionType(int value)Sets the compression type.
getColorType()Gets the color type for jpeg image.
setColorType(int value)Sets the color type for jpeg image.
getBitsPerChannel()Gets bits per channel for lossless jpeg image.
setBitsPerChannel(byte value)Sets bits per channel for lossless jpeg image.
getQuality()Gets image quality.
setQuality(int value)Sets image quality.
getScaledQuality()The scaled quality.
getRdOptSettings()Gets the RD optimizer settings.
setRdOptSettings(RdOptimizerSettings value)Sets the RD optimizer settings.
getRgbColorProfile()The destination RGB color profile for CMYK jpeg images.
setRgbColorProfile(StreamSource value)The destination RGB color profile for CMYK jpeg images.
getCmykColorProfile()The destination CMYK color profile for CMYK jpeg images.
setCmykColorProfile(StreamSource value)The destination CMYK color profile for CMYK jpeg images.
getJpegLsAllowedLossyError()Gets the JPEG-LS difference bound for near-lossless coding (NEAR parameter from the JPEG-LS specification).
setJpegLsAllowedLossyError(int value)Sets the JPEG-LS difference bound for near-lossless coding (NEAR parameter from the JPEG-LS specification).
getJpegLsInterleaveMode()Gets the JPEG-LS interleave mode.
setJpegLsInterleaveMode(int value)Sets the JPEG-LS interleave mode.
getJpegLsPreset()Gets the JPEG-LS preset parameters.
setJpegLsPreset(JpegLsPresetCodingParameters value)Sets the JPEG-LS preset parameters.
getHorizontalSampling()Gets the horizontal subsamplings for each component.
setHorizontalSampling(byte[] value)Sets the horizontal subsamplings for each component.
getVerticalSampling()Gets the vertical subsamplings for each component.
setVerticalSampling(byte[] value)Sets the vertical subsamplings for each component.
getSampleRoundingMode()Gets the sample rounding mode to fit an 8-bit value to an n-bit value.
setSampleRoundingMode(int value)Sets the sample rounding mode to fit an 8-bit value to an n-bit value.
getPreblendAlphaIfPresent()Gets a value indicating whether red, green and blue components should be mixed with a background color, if alpha channel is present.
setPreblendAlphaIfPresent(boolean value)Sets a value indicating whether red, green and blue components should be mixed with a background color, if alpha channel is present.
getResolutionUnit()Gets the resolution unit.
setResolutionUnit(byte value)Sets the resolution unit.

Example: This example demonstrates the use of different classes from SaveOptions Namespace for export purposes.

This example demonstrates the use of different classes from SaveOptions Namespace for export purposes. An image of type Gif is loaded into an instance of Image and then exported out to several formats.

String dir = "c:\\temp\\";

//Load an existing image (of type Gif) in an instance of Image class
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    //Export to BMP file format using the default options
    image.save(dir + "output.bmp", new com.aspose.imaging.imageoptions.BmpOptions());

    //Export to JPEG file format using the default options
    image.save(dir + "output.jpeg", new com.aspose.imaging.imageoptions.JpegOptions());

    //Export to PNG file format using the default options
    image.save(dir + "output.png", new com.aspose.imaging.imageoptions.PngOptions());

    //Export to TIFF file format using the default options
    image.save(dir + "output.tif", new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default));
} finally {
    image.dispose();
}

Example: The following example shows how to convert a multipage vector image to JPEG format in general way without referencing to a particular image type.

String dir = "C:\\aspose.imaging\\net\\misc\\ImagingReleaseQATester\\Tests\\testdata\\2548";
String inputFilePath = (dir + "Multipage.cdr");
String outputFilePath = (dir + "Multipage.cdr.jpeg");

com.aspose.imaging.ImageOptionsBase exportOptions = new com.aspose.imaging.imageoptions.JpegOptions();

try (com.aspose.imaging.Image image = com.aspose.imaging.Image.load(inputFilePath))
{
    exportOptions.setMultiPageOptions(null);

    // Export only first two pages. In fact, only one page will be rasterized because JPEG is not a multi-page format.
    com.aspose.imaging.IMultipageImage multipageImage = (image instanceof com.aspose.imaging.IMultipageImage) ? (com.aspose.imaging.IMultipageImage) image : null;
    if (multipageImage != null && (multipageImage.getPages() != null && multipageImage.getPageCount() > 2))
    {
        exportOptions.setMultiPageOptions(new com.aspose.imaging.imageoptions.MultiPageOptions(new com.aspose.imaging.IntRange(0, 2)));
    }

    if (image instanceof com.aspose.imaging.VectorImage)
    {
        com.aspose.imaging.imageoptions.VectorRasterizationOptions defaultOptions = (com.aspose.imaging.imageoptions.VectorRasterizationOptions) image.getDefaultOptions(new Object[]{Color.getWhite(), image.getWidth(), image.getHeight()});
        exportOptions.setVectorRasterizationOptions(defaultOptions);
        defaultOptions.setTextRenderingHint(com.aspose.imaging.TextRenderingHint.SingleBitPerPixel);
        defaultOptions.setSmoothingMode(com.aspose.imaging.SmoothingMode.None);
    }

    image.save(outputFilePath, exportOptions);
}

JpegOptions()

public JpegOptions()

Initializes a new instance of the JpegOptions class.

JpegOptions(JpegOptions jpegOptions)

public JpegOptions(JpegOptions jpegOptions)

Initializes a new instance of the JpegOptions class.

Parameters:

ParameterTypeDescription
jpegOptionsJpegOptionsThe JPEG options.

getDefaultMemoryAllocationLimit()

public int getDefaultMemoryAllocationLimit()

Gets the default memory allocation limit.

Returns: int - The default memory allocation limit.

setDefaultMemoryAllocationLimit(int value)

public void setDefaultMemoryAllocationLimit(int value)

Sets the default memory allocation limit.

Parameters:

ParameterTypeDescription
valueintThe default memory allocation limit.

getXmpData()

public XmpPacketWrapper getXmpData()

Gets the XMP metadata container.

Returns: XmpPacketWrapper - The XMP data container.

setXmpData(XmpPacketWrapper value)

public void setXmpData(XmpPacketWrapper value)

Sets the XMP metadata container.

Parameters:

ParameterTypeDescription
valueXmpPacketWrapperThe XMP data container.

getJfif()

public JFIFData getJfif()

Gets the jfif.

Returns: JFIFData

setJfif(JFIFData value)

public void setJfif(JFIFData value)

Sets the jfif.

Parameters:

ParameterTypeDescription
valueJFIFData

getComment()

public String getComment()

Gets the jpeg file comment.

Returns: java.lang.String

setComment(String value)

public void setComment(String value)

Sets the jpeg file comment.

Parameters:

ParameterTypeDescription
valuejava.lang.String

getExifData()

public JpegExifData getExifData()

Get or set exif data container

Returns: JpegExifData

setExifData(JpegExifData value)

public void setExifData(JpegExifData value)

Get or set exif data container

Parameters:

ParameterTypeDescription
valueJpegExifData

getCompressionType()

public int getCompressionType()

Gets the compression type.

Returns: int

setCompressionType(int value)

public void setCompressionType(int value)

Sets the compression type.

Parameters:

ParameterTypeDescription
valueint

Example: 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();
}

getColorType()

public int getColorType()

Gets the color type for jpeg image.

Returns: int

Example: 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();
}

setColorType(int value)

public void setColorType(int value)

Sets the color type for jpeg image.

Parameters:

ParameterTypeDescription
valueint

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

String dir = "c:\\temp\\";

// Load a BMP image from a file.
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
    // Do some image processing.

    // Use additional options to specify the desired image parameters.
    com.aspose.imaging.imageoptions.JpegOptions saveOptions = new com.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.setBitsPerChannel((byte) 8);

    // Set the progressive type of compression.
    saveOptions.setCompressionType(com.aspose.imaging.fileformats.jpeg.JpegCompressionMode.Progressive);

    // Set the image quality. It is a value between 1 and 100.
    saveOptions.setQuality(100);

    // Set the horizontal/vertical resolution to 96 dots per inch.
    saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));
    saveOptions.setResolutionUnit(com.aspose.imaging.ResolutionUnit.Inch);

    // If the source image is colored, it will be converted to grayscaled.
    saveOptions.setColorType(com.aspose.imaging.fileformats.jpeg.JpegCompressionColorMode.Grayscale);

    // Use a palette to reduce the output size.
    saveOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.create8BitGrayscale(false));

    image.save(dir + "sample.palettized.jpg", saveOptions);
} finally {
    image.dispose();
}

getBitsPerChannel()

public byte getBitsPerChannel()

Gets bits per channel for lossless jpeg image. Now we support from 2 to 8 bits per channel.

Returns: byte

setBitsPerChannel(byte value)

public void setBitsPerChannel(byte value)

Sets bits per channel for lossless jpeg image. Now we support from 2 to 8 bits per channel.

Parameters:

ParameterTypeDescription
valuebyte

Example: 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();
}

getQuality()

public int getQuality()

Gets image quality.

Returns: int

setQuality(int value)

public void setQuality(int value)

Sets image quality.

Parameters:

ParameterTypeDescription
valueint

Example: 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();
}

getScaledQuality()

public int getScaledQuality()

The scaled quality.

Returns: int

getRdOptSettings()

public RdOptimizerSettings getRdOptSettings()

Gets the RD optimizer settings.

Returns: RdOptimizerSettings - The RD optimizer settings.

setRdOptSettings(RdOptimizerSettings value)

public void setRdOptSettings(RdOptimizerSettings value)

Sets the RD optimizer settings.

Parameters:

ParameterTypeDescription
valueRdOptimizerSettingsThe RD optimizer settings.

getRgbColorProfile()

public StreamSource getRgbColorProfile()

The destination RGB color profile for CMYK jpeg images. Use for saving images. Must be in pair with CMYKColorProfile for correct color conversion.

Returns: StreamSource

setRgbColorProfile(StreamSource value)

public void setRgbColorProfile(StreamSource value)

The destination RGB color profile for CMYK jpeg images. Use for saving images. Must be in pair with CMYKColorProfile for correct color conversion.

Parameters:

ParameterTypeDescription
valueStreamSource

Example: The following example loads PNG and saves it to CMYK JPEG using custom ICC profile. 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();
}

getCmykColorProfile()

public StreamSource getCmykColorProfile()

The destination CMYK color profile for CMYK jpeg images. Use for saving images. Must be in pair with RGBColorProfile for correct color conversion.

Returns: StreamSource

setCmykColorProfile(StreamSource value)

public void setCmykColorProfile(StreamSource value)

The destination CMYK color profile for CMYK jpeg images. Use for saving images. Must be in pair with RGBColorProfile for correct color conversion.

Parameters:

ParameterTypeDescription
valueStreamSource

Example: The following example loads PNG and saves it to CMYK JPEG using custom ICC profile. 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();
}

getJpegLsAllowedLossyError()

public int getJpegLsAllowedLossyError()

Gets the JPEG-LS difference bound for near-lossless coding (NEAR parameter from the JPEG-LS specification).

Returns: int

setJpegLsAllowedLossyError(int value)

public void setJpegLsAllowedLossyError(int value)

Sets the JPEG-LS difference bound for near-lossless coding (NEAR parameter from the JPEG-LS specification).

Parameters:

ParameterTypeDescription
valueint

getJpegLsInterleaveMode()

public int getJpegLsInterleaveMode()

Gets the JPEG-LS interleave mode.

Returns: int

setJpegLsInterleaveMode(int value)

public void setJpegLsInterleaveMode(int value)

Sets the JPEG-LS interleave mode.

Parameters:

ParameterTypeDescription
valueint

getJpegLsPreset()

public JpegLsPresetCodingParameters getJpegLsPreset()

Gets the JPEG-LS preset parameters.

Returns: JpegLsPresetCodingParameters

setJpegLsPreset(JpegLsPresetCodingParameters value)

public void setJpegLsPreset(JpegLsPresetCodingParameters value)

Sets the JPEG-LS preset parameters.

Parameters:

ParameterTypeDescription
valueJpegLsPresetCodingParameters

getHorizontalSampling()

public byte[] getHorizontalSampling()

Gets the horizontal subsamplings for each component.

Returns: byte[]

setHorizontalSampling(byte[] value)

public void setHorizontalSampling(byte[] value)

Sets the horizontal subsamplings for each component.

Parameters:

ParameterTypeDescription
valuebyte[]

getVerticalSampling()

public byte[] getVerticalSampling()

Gets the vertical subsamplings for each component.

Returns: byte[]

setVerticalSampling(byte[] value)

public void setVerticalSampling(byte[] value)

Sets the vertical subsamplings for each component.

Parameters:

ParameterTypeDescription
valuebyte[]

getSampleRoundingMode()

public int getSampleRoundingMode()

Gets the sample rounding mode to fit an 8-bit value to an n-bit value. P:JpegOptions.BitsPerChannel

Returns: int

setSampleRoundingMode(int value)

public void setSampleRoundingMode(int value)

Sets the sample rounding mode to fit an 8-bit value to an n-bit value. P:JpegOptions.BitsPerChannel

Parameters:

ParameterTypeDescription
valueint

getPreblendAlphaIfPresent()

public boolean getPreblendAlphaIfPresent()

Gets a value indicating whether red, green and blue components should be mixed with a background color, if alpha channel is present.

Returns: boolean

setPreblendAlphaIfPresent(boolean value)

public void setPreblendAlphaIfPresent(boolean value)

Sets a value indicating whether red, green and blue components should be mixed with a background color, if alpha channel is present.

Parameters:

ParameterTypeDescription
valueboolean

getResolutionUnit()

public final byte getResolutionUnit()

Gets the resolution unit.

Returns: byte - the resolution unit.

Example: 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();
}

setResolutionUnit(byte value)

public final void setResolutionUnit(byte value)

Sets the resolution unit.

Parameters:

ParameterTypeDescription
valuebytethe resolution unit.

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

String dir = "c:\\temp\\";

// Load a BMP image from a file.
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
    // Do some image processing.

    // Use additional options to specify the desired image parameters.
    com.aspose.imaging.imageoptions.JpegOptions saveOptions = new com.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.setBitsPerChannel((byte) 8);

    // Set the progressive type of compression.
    saveOptions.setCompressionType(com.aspose.imaging.fileformats.jpeg.JpegCompressionMode.Progressive);

    // Set the image quality. It is a value between 1 and 100.
    saveOptions.setQuality(100);

    // Set the horizontal/vertical resolution to 96 dots per inch.
    saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));
    saveOptions.setResolutionUnit(com.aspose.imaging.ResolutionUnit.Inch);

    // If the source image is colored, it will be converted to grayscaled.
    saveOptions.setColorType(com.aspose.imaging.fileformats.jpeg.JpegCompressionColorMode.Grayscale);

    // Use a palette to reduce the output size.
    saveOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.create8BitGrayscale(false));

    image.save(dir + "sample.palettized.jpg", saveOptions);
} finally {
    image.dispose();
}