Packages

 

com.aspose.imaging.fileformats.jpeg2000

Class Jpeg2000Image

  • All Implemented Interfaces:
    IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, com.aspose.imaging_internal.IPixelsSaver, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class Jpeg2000Image
    extends RasterCachedImage

    Jpeg2000 library main class

    Code example:

    This example shows how to load a JPEG2000 image from a file and save it to PNG.


    String dir = "c:\\temp\\";
    
    // Load a JPEG2000 image.
    com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = new com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image(dir + "sample.jp2");
    try {
        // Save to PNG
        jpeg2000Image.save(dir + "sample.output.png", new com.aspose.imaging.imageoptions.PngOptions());
    } finally {
        jpeg2000Image.dispose();
    }
    

    • Constructor Detail

      • Jpeg2000Image

        public Jpeg2000Image(String path)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        path - The path to load image from and initialize pixel and palette data with.
        Code example:

        This example shows how to load a JPEG2000 image from a file and save it to PNG.


        String dir = "c:\\temp\\";
        
        // Load a JPEG2000 image.
        com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = new com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image(dir + "sample.jp2");
        try {
            // Save to PNG
            jpeg2000Image.save(dir + "sample.output.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            jpeg2000Image.dispose();
        }
        

      • Jpeg2000Image

        public Jpeg2000Image(String path,
                             int bitsPerPixel)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        path - The path to load image from and initialize pixel and palette data with
        bitsPerPixel - The bits per pixel.
      • Jpeg2000Image

        public Jpeg2000Image(InputStream stream)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        stream - The stream to load image from and initialize pixel and palette data with.
        Code example:

        This example shows how to load a JPEG2000 image from a file stream and save it to PNG.


        String dir = "c:\\temp\\";
        
        // Load a JPEG2000 image from stream.
        java.io.FileInputStream stream = new java.io.FileInputStream(dir + "sample.jp2");
        com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = new com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image(stream);
        try {
            // Save to PNG
            jpeg2000Image.save(dir + "sample.output.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            jpeg2000Image.dispose();
            stream.close();
        }
        

      • Jpeg2000Image

        public Jpeg2000Image(InputStream stream,
                             int bitsPerPixel)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        stream - The stream to load image from and initialize pixel and palette data with.
        bitsPerPixel - The bits per pixel.
      • Jpeg2000Image

        public Jpeg2000Image(int width,
                             int height)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        width - The image width
        height - The image height
        Code example:

        This example shows how to create a JPEG2000 image and save it to a file.


        String dir = "c:\\temp\\";
        
        // Create a JPEG2000 image of 100x100 px.
        com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = new com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image(100, 100);
        try {
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(jpeg2000Image);
        
            // 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, jpeg2000Image.getBounds());
        
            // Save to a file
            jpeg2000Image.save(dir + "sample.output.jp2", new com.aspose.imaging.imageoptions.Jpeg2000Options());
        } finally {
            jpeg2000Image.dispose();
        }
        

      • Jpeg2000Image

        public Jpeg2000Image(int width,
                             int height,
                             Jpeg2000Options options)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        width - The image width
        height - The image height
        options - The options.
        Code example:

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


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.imageoptions.Jpeg2000Options createOptions = new com.aspose.imaging.imageoptions.Jpeg2000Options();
        
        // Use the irreversible Discrete Wavelet Transform 9-7
        createOptions.setIrreversible(true);
        
        // JP2 is the "container" format for JPEG 2000 codestreams.
        // J2K is raw compressed data, without a wrapper.
        createOptions.setCodec(com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Codec.J2K);
        
        // Create a JPEG2000 image of 100x100 px.
        com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = new com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image(100, 100, createOptions);
        try {
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(jpeg2000Image);
        
            // 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, jpeg2000Image.getBounds());
        
            // Save to a file
            jpeg2000Image.save(dir + "sample.output.j2k");
        } finally {
            jpeg2000Image.dispose();
        }
        

      • Jpeg2000Image

        public Jpeg2000Image(int width,
                             int height,
                             int bitsCount)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        width - The image width
        height - The image height
        bitsCount - The bits count.
      • Jpeg2000Image

        public Jpeg2000Image(RasterImage image)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        image - The image.
        Code example:

        This example shows how to create a JPEG2000 image with from another raster image.


        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());
        
            // Create a JPEG2000 image based on the PNG image.
            com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = new com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image(pngImage);
            try {
                // Save to a file
                jpeg2000Image.save(dir + "output.jp2", new com.aspose.imaging.imageoptions.Jpeg2000Options());
            } finally {
        
                jpeg2000Image.dispose();
            }
        } finally {
            pngImage.dispose();
        }
        

      • Jpeg2000Image

        public Jpeg2000Image(RasterImage rasterImage,
                             int bitsPerPixel)

        Initializes a new instance of the Jpeg2000Image class.

        Parameters:
        rasterImage - The image to initialize pixel and palette data with.
        bitsPerPixel - The bits per pixel.
    • Method Detail

      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
      • getRawLineSize

        public int getRawLineSize()

        Gets the raw line size in bytes.

        Overrides:
        getRawLineSize in class RasterImage
        Returns:
        The raw line size in bytes.
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets image depth (bits per pixel)

        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
      • getHorizontalResolution

        public double getHorizontalResolution()

        Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.

        Overrides:
        getHorizontalResolution in class RasterImage
        Returns:
        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.

        Code example:

        The following example shows how to set horizontal/vertical resolution of a JPEG2000 image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jp2");
        try {
            com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = (com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image) image;
        
            // Get horizontal and vertical resolution of the Jpeg2000Image.
            double horizontalResolution = jpeg2000Image.getHorizontalResolution();
            double verticalResolution = jpeg2000Image.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");
                jpeg2000Image.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + jpeg2000Image.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + jpeg2000Image.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        

      • setHorizontalResolution

        public void setHorizontalResolution(double value)

        Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.

        Overrides:
        setHorizontalResolution in class RasterImage
        Parameters:
        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.

      • getVerticalResolution

        public double getVerticalResolution()

        Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.

        Overrides:
        getVerticalResolution in class RasterImage
        Returns:
        The vertical 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.

        Code example:

        The following example shows how to set horizontal/vertical resolution of a JPEG2000 image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jp2");
        try {
            com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image jpeg2000Image = (com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Image) image;
        
            // Get horizontal and vertical resolution of the Jpeg2000Image.
            double horizontalResolution = jpeg2000Image.getHorizontalResolution();
            double verticalResolution = jpeg2000Image.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");
                jpeg2000Image.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + jpeg2000Image.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + jpeg2000Image.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 72.0
        // The vertical resolution, in pixels per inch: 72.0
        

      • setVerticalResolution

        public void setVerticalResolution(double value)

        Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.

        Overrides:
        setVerticalResolution in class RasterImage
        Parameters:
        value - The vertical 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.

      • getComments

        public String[] getComments()

        Gets or sets the comments.

        Returns:
        The comments.
      • setComments

        public void setComments(String[] value)

        Gets or sets the comments.

        Parameters:
        value - The comments.
      • getCodec

        public int getCodec()

        Gets the codec.

        Returns:
        The codec.