Packages

 

com.aspose.imaging.imageoptions

Class Jpeg2000Options

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


    public class Jpeg2000Options
    extends ImageOptionsBase

    The Jpeg2000 file format options.

    Code example:

    The following example shows how to convert a multipage vector image to JPEG 2000 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.j2k");
    
    com.aspose.imaging.ImageOptionsBase exportOptions = new com.aspose.imaging.imageoptions.Jpeg2000Options();
    
    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 2000 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);
    }
    

    • Constructor Detail

      • Jpeg2000Options

        public Jpeg2000Options()

        Initializes a new instance of the Jpeg2000Options class.

      • Jpeg2000Options

        public Jpeg2000Options(Jpeg2000Options jpeg2000Options)

        Initializes a new instance of the Jpeg2000Options class.

        Parameters:
        jpeg2000Options - The Jpeg2000 file format options to copy settings from.
    • Method Detail

      • getComments

        public String[] getComments()

        Gets or sets the Jpeg comment markers.

        Returns:
        The Jpeg comment markers.
      • setComments

        public void setComments(String[] value)

        Gets or sets the Jpeg comment markers.

        Parameters:
        value - The Jpeg comment markers.
      • getCodec

        public int getCodec()

        Gets or sets the JPEG2000 codec

        Returns:
        The JPEG2000 codec
        See Also:
        Jpeg2000Codec
      • setCodec

        public void setCodec(int value)

        Gets or sets the JPEG2000 codec

        Parameters:
        value - The JPEG2000 codec
        See Also:
        Jpeg2000Codec
        Code example:

        This example shows how to create a PNG image and save it to JPEG2000 with the desired options.


        String dir = "c:\\temp\\";
        
        // Create a PNG image of 100x100 px.
        com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(100, 100);
        try {
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(pngImage);
        
            // Fill the entire image in red.
            com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            graphics.fillRectangle(brush, pngImage.getBounds());
        
            com.aspose.imaging.imageoptions.Jpeg2000Options saveOptions = new com.aspose.imaging.imageoptions.Jpeg2000Options();
        
            // Use the irreversible Discrete Wavelet Transform 9-7
            saveOptions.setIrreversible(true);
        
            // JP2 is the "container" format for JPEG 2000 codestreams.
            // J2K is raw compressed data, without a wrapper.
            saveOptions.setCodec(com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Codec.J2K);
        
            // Save to a file
            pngImage.save(dir + "output.j2k", saveOptions);
        } finally {
            pngImage.dispose();
        }
        

      • getCompressionRatios

        public int[] getCompressionRatios()

        Gets or sets the Array of compression ratio. Different compression ratios for successive layers. The rate specified for each quality level is the desired compression factor. Decreasing ratios required.

        Returns:
        The compression ratios.
      • setCompressionRatios

        public void setCompressionRatios(int[] value)

        Gets or sets the Array of compression ratio. Different compression ratios for successive layers. The rate specified for each quality level is the desired compression factor. Decreasing ratios required.

        Parameters:
        value - The compression ratios.
      • getIrreversible

        public boolean getIrreversible()

        Gets a value indicating whether use the irreversible DWT 9-7 (true) or use lossless DWT 5-3 compression (default).

        Returns:
        a value indicating whether use the irreversible DWT 9-7 (true) or use lossless DWT 5-3 compression
      • setIrreversible

        public void setIrreversible(boolean value)

        Sets a value indicating whether use the irreversible DWT 9-7 (true) or use lossless DWT 5-3 compression (default).

        Parameters:
        value - a value indicating whether use the irreversible DWT 9-7 (true) or use lossless DWT 5-3 compression
        Code example:

        This example shows how to create a PNG image and save it to JPEG2000 with the desired options.


        String dir = "c:\\temp\\";
        
        // Create a PNG image of 100x100 px.
        com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(100, 100);
        try {
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(pngImage);
        
            // Fill the entire image in red.
            com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            graphics.fillRectangle(brush, pngImage.getBounds());
        
            com.aspose.imaging.imageoptions.Jpeg2000Options saveOptions = new com.aspose.imaging.imageoptions.Jpeg2000Options();
        
            // Use the irreversible Discrete Wavelet Transform 9-7
            saveOptions.setIrreversible(true);
        
            // JP2 is the "container" format for JPEG 2000 codestreams.
            // J2K is raw compressed data, without a wrapper.
            saveOptions.setCodec(com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Codec.J2K);
        
            // Save to a file
            pngImage.save(dir + "output.j2k", saveOptions);
        } finally {
            pngImage.dispose();
        }