Packages

 

com.aspose.imaging.imageoptions

Class JpegOptions

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public class JpegOptions
    extends ImageOptionsBase

    The jpeg file format create options.

    Code example:

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

    • Constructor Detail

      • JpegOptions

        public JpegOptions()

        Initializes a new instance of the JpegOptions class.

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

      • JpegOptions

        public JpegOptions(JpegOptions jpegOptions)

        Initializes a new instance of the JpegOptions class.

        Parameters:
        jpegOptions - The JPEG options.
    • Method Detail

      • getDefaultMemoryAllocationLimit

        public int getDefaultMemoryAllocationLimit()

        Gets the default memory allocation limit.

        Returns:
        The default memory allocation limit.
      • setDefaultMemoryAllocationLimit

        public void setDefaultMemoryAllocationLimit(int value)

        Sets the default memory allocation limit.

        Parameters:
        value - The default memory allocation limit.
      • getJfif

        public JFIFData getJfif()

        Gets the jfif.

      • setJfif

        public void setJfif(JFIFData value)

        Sets the jfif.

      • getComment

        public String getComment()

        Gets the jpeg file comment.

      • setComment

        public void setComment(String value)

        Sets the jpeg file comment.

      • getExifData

        public JpegExifData getExifData()

        Get or set exif data container

      • setExifData

        public void setExifData(JpegExifData value)

        Get or set exif data container

      • getCompressionType

        public int getCompressionType()

        Gets the compression type.

      • setCompressionType

        public void setCompressionType(int value)

        Sets the compression type.

        Code 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.

        Code 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

        public void setColorType(int value)

        Sets the color type for jpeg image.

        Code 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.

      • setBitsPerChannel

        public void setBitsPerChannel(byte value)

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

        Code 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.

      • setQuality

        public void setQuality(int value)

        Sets image quality.

        Code 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.

      • getRdOptSettings

        public RdOptimizerSettings getRdOptSettings()

        Gets the RD optimizer settings.

        Returns:
        The RD optimizer settings.
      • setRdOptSettings

        public void setRdOptSettings(RdOptimizerSettings value)

        Sets the RD optimizer settings.

        Parameters:
        value - The 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.

      • setRgbColorProfile

        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.

        Code example:

        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.

      • setCmykColorProfile

        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.

        Code example:

        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).

      • setJpegLsAllowedLossyError

        public void setJpegLsAllowedLossyError(int value)

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

      • getJpegLsInterleaveMode

        public int getJpegLsInterleaveMode()

        Gets the JPEG-LS interleave mode.

      • setJpegLsInterleaveMode

        public void setJpegLsInterleaveMode(int value)

        Sets the JPEG-LS interleave mode.

      • getHorizontalSampling

        public byte[] getHorizontalSampling()

        Gets the horizontal subsamplings for each component.

      • setHorizontalSampling

        public void setHorizontalSampling(byte[] value)

        Sets the horizontal subsamplings for each component.

      • getVerticalSampling

        public byte[] getVerticalSampling()

        Gets the vertical subsamplings for each component.

      • setVerticalSampling

        public void setVerticalSampling(byte[] value)

        Sets the vertical subsamplings for each component.

      • getSampleRoundingMode

        public int getSampleRoundingMode()

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

      • setSampleRoundingMode

        public void setSampleRoundingMode(int value)

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

      • 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.

      • setPreblendAlphaIfPresent

        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.

      • getResolutionUnit

        public final byte getResolutionUnit()

        Gets the resolution unit.

        Returns:
        the resolution unit.
        Code 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

        public final void setResolutionUnit(byte value)

        Sets the resolution unit.

        Parameters:
        value - the resolution unit.
        Code 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();
        }