Packages

 

com.aspose.imaging

Interfaces

Classes

Exceptions

com.aspose.imaging

Class RasterImage

  • All Implemented Interfaces:
    IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, com.aspose.imaging_internal.IPixelsSaver, com.aspose.imaging_internal.progressmanagement.IProgressEventHandler, com.aspose.imaging_internal.progressmanagement.IProgressInformer, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable
    Direct Known Subclasses:
    RasterCachedImage


    public abstract class RasterImage
    extends Image
    implements IRasterImageArgb32PixelLoader, com.aspose.imaging_internal.IPixelsSaver

    Represents a raster image supporting raster graphics operations.

    Code example:

    This example shows how to load pixel information in an array of colors, manipulates the array and set it back to the image.


    String dir = "c:\\temp\\";
    
    // Create an instance of GifOptions and set its various properties including the Source property
    com.aspose.imaging.imageoptions.GifOptions gifOptions = new com.aspose.imaging.imageoptions.GifOptions();
    gifOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dir + "output.gif", false));
    
    // Create an instance of Image
    com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(gifOptions, 500, 500);
    try {
        // Get the pixels of image by specifying the area as image boundary
        com.aspose.imaging.Color[] pixels = image.loadPixels(image.getBounds());
    
        // Loop over the array and sets color of alternative indexed pixel
        for (int index = 0; index < pixels.length; index++) {
            if (index % 2 == 0) {
                // Set the indexed pixel color to yellow
                pixels[index] = com.aspose.imaging.Color.getYellow();
            } else {
                // Set the indexed pixel color to blue
                pixels[index] = com.aspose.imaging.Color.getBlue();
            }
        }
    
        // Apply the pixel changes to the image
        image.savePixels(image.getBounds(), pixels);
    
        // Save all changes.
        image.save();
    } finally {
        image.dispose();
    }
    

    • Method Detail

      • getPremultiplyComponents

        public boolean getPremultiplyComponents()

        Gets or sets a value indicating whether the image components must be premultiplied.

        Returns:
        true if the image components must be premultiplied; otherwise, false.
      • setPremultiplyComponents

        public void setPremultiplyComponents(boolean value)

        Gets or sets a value indicating whether the image components must be premultiplied.

        Parameters:
        value - true if the image components must be premultiplied; otherwise, false.
        Code example:

        The following example creates a new raster image, saves the specified semi-transparent pixels, then loads those pixels and gets final colors in the premultiplied form.


        int imageWidth = 3;
        int imageHeight = 2;
        
        com.aspose.imaging.Color[] colors = new com.aspose.imaging.Color[]
                {
                        com.aspose.imaging.Color.fromArgb(127, 255, 0, 0),
                        com.aspose.imaging.Color.fromArgb(127, 0, 255, 0),
                        com.aspose.imaging.Color.fromArgb(127, 0, 0, 255),
                        com.aspose.imaging.Color.fromArgb(127, 255, 255, 0),
                        com.aspose.imaging.Color.fromArgb(127, 255, 0, 255),
                        com.aspose.imaging.Color.fromArgb(127, 0, 255, 255),
                };
        
        com.aspose.imaging.imageoptions.PngOptions createOptions = new com.aspose.imaging.imageoptions.PngOptions();
        createOptions.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        createOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha);
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.create(createOptions, imageWidth, imageHeight);
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Save pixels for the whole image.
            rasterImage.savePixels(rasterImage.getBounds(), colors);
        
            // The pixels are stored in the original image in the non-premultiplied form.
            // Need to specify the corresponding option explicitly to obtain premultiplied color components.
            // The premultiplied color components are calculated by the formulas:
            // red = original_red * alpha / 255;
            // green = original_green * alpha / 255;
            // blue = original_blue * alpha / 255;
            rasterImage.setPremultiplyComponents(true);
            com.aspose.imaging.Color[] premultipliedColors = rasterImage.loadPixels(rasterImage.getBounds());
        
            for (int i = 0; i < colors.length; i++) {
                System.out.println("Original color: " + colors[i].toString());
                System.out.println("Premultiplied color: " + premultipliedColors[i].toString());
            }
        } finally {
            image.dispose();
        }
        

      • getUseRawData

        public boolean getUseRawData()

        Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.

        Returns:
        true if use raw data loading when the raw data loading is available.; otherwise, false.
      • setUseRawData

        public void setUseRawData(boolean value)

        Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.

        Parameters:
        value - true if use raw data loading when the raw data loading is available.; otherwise, false.
      • getUpdateXmpData

        public boolean getUpdateXmpData()

        Gets or sets a value indicating whether to update the XMP metadata.

        Returns:
        true if update the XMP metadata; otherwise, false.
      • setUpdateXmpData

        public void setUpdateXmpData(boolean value)

        Gets or sets a value indicating whether to update the XMP metadata.

        Parameters:
        value - true if update the XMP metadata; otherwise, false.
      • getXmpData

        public XmpPacketWrapper getXmpData()

        Gets or sets the XMP metadata.

        Returns:
        The XMP metadata.
      • setXmpData

        public void setXmpData(XmpPacketWrapper value)

        Gets or sets the XMP metadata.

        Parameters:
        value - The XMP metadata.
      • getRawIndexedColorConverter

        public IIndexedColorConverter getRawIndexedColorConverter()

        Gets or sets the indexed color converter

        Returns:
        The indexed color converter
      • setRawIndexedColorConverter

        public void setRawIndexedColorConverter(IIndexedColorConverter value)

        Gets or sets the indexed color converter

        Parameters:
        value - The indexed color converter
      • getRawCustomColorConverter

        public IColorConverter getRawCustomColorConverter()

        Gets or sets the custom color converter

        Returns:
        The custom color converter
      • setRawCustomColorConverter

        public void setRawCustomColorConverter(IColorConverter value)

        Gets or sets the custom color converter

        Parameters:
        value - The custom color converter
      • getRawFallbackIndex

        public int getRawFallbackIndex()

        Gets or sets the fallback index to use when palette index is out of bounds

        Returns:
        The fallback index to use when palette index is out of bounds
      • setRawFallbackIndex

        public void setRawFallbackIndex(int value)

        Gets or sets the fallback index to use when palette index is out of bounds

        Parameters:
        value - The fallback index to use when palette index is out of bounds
      • getRawDataFormat

        public PixelDataFormat getRawDataFormat()

        Gets the raw data format.

        Returns:
        The raw data format.
        Code example:

        The following example loads raster images and prints information about raw data format and alpha channel.


        
        // The image files to load.
        String[] fileNames = new String[]
                {
                        "c:\\temp\\sample.bmp",
                        "c:\\temp\\alpha.png",
                };
        
        for (String fileName : fileNames) {
            com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName);
            try {
                com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
                System.out.println(
                        "ImageFile=" + fileName +
                                " FileFormat=" + rasterImage.getRawDataFormat() +
                                " HasAlpha=" + rasterImage.hasAlpha());
            } finally {
                image.dispose();
            }
        }
        
        // The output may look like this:
        // ImageFile=c:\temp\sample.bmp FileFormat=Rgb24Bpp, used channels: 8,8,8 HasAlpha=false
        // ImageFile=c:\temp\alpha.png FileFormat=RGBA32Bpp, used channels: 8,8,8,8 HasAlpha=true
        

      • getRawLineSize

        public int getRawLineSize()

        Gets the raw line size in bytes.

        Returns:
        The raw line size in bytes.
      • isRawDataAvailable

        public boolean isRawDataAvailable()

        Gets a value indicating whether raw data loading is available.

        Specified by:
        isRawDataAvailable in interface IRasterImageRawDataLoader
        Returns:
        true if this raw data loading is available; otherwise, false.
      • getHorizontalResolution

        public double getHorizontalResolution()

        Gets or sets the horizontal resolution, in pixels per inch, of this 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 raster image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jpg");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Get horizontal and vertical resolution of the image
            double horizontalResolution = rasterImage.getHorizontalResolution();
            double verticalResolution = rasterImage.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");
                rasterImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + rasterImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + rasterImage.getVerticalResolution());
            }
        
            // 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
        } finally {
            image.dispose();
        }
        

      • setHorizontalResolution

        public void setHorizontalResolution(double value)

        Gets or sets the horizontal resolution, in pixels per inch, of this 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.

        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 raster image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jpg");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Get horizontal and vertical resolution of the image
            double horizontalResolution = rasterImage.getHorizontalResolution();
            double verticalResolution = rasterImage.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");
                rasterImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + rasterImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + rasterImage.getVerticalResolution());
            }
        
            // 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
        } finally {
            image.dispose();
        }
        

      • setVerticalResolution

        public void setVerticalResolution(double value)

        Gets or sets the vertical resolution, in pixels per inch, of this 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.

      • hasTransparentColor

        public boolean hasTransparentColor()

        Gets a value indicating whether image has transparent color.

      • setTransparentColor

        public void setTransparentColor(boolean value)

        Gets a value indicating whether image has transparent color.

      • hasAlpha

        public boolean hasAlpha()

        Gets a value indicating whether this instance has alpha.

        Returns:
        true if this instance has alpha; otherwise, false.
        Code example:

        The following example loads raster images and prints information about raw data format and alpha channel.


        
        // The image files to load.
        String[] fileNames = new String[]
                {
                        "c:\\temp\\sample.bmp",
                        "c:\\temp\\alpha.png",
                };
        
        for (String fileName : fileNames) {
            com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName);
            try {
                com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
                System.out.println(
                        "ImageFile=" + fileName +
                                " FileFormat=" + rasterImage.getRawDataFormat() +
                                " HasAlpha=" + rasterImage.hasAlpha());
            } finally {
                image.dispose();
            }
        }
        
        // The output may look like this:
        // ImageFile=c:\temp\sample.bmp FileFormat=Rgb24Bpp, used channels: 8,8,8 HasAlpha=false
        // ImageFile=c:\temp\alpha.png FileFormat=RGBA32Bpp, used channels: 8,8,8,8 HasAlpha=true
        

      • getTransparentColor

        public Color getTransparentColor()

        Gets the image transparent color.

      • setTransparentColor

        public void setTransparentColor(Color value)

        Gets the image transparent color.

      • getImageOpacity

        public float getImageOpacity()

        Gets opacity of this image.

        Returns:
        The opacity value between 0.0 (fully transparent) and 1.0 (fully opaque).
      • getModifyDate

        public Date getModifyDate(boolean useDefault)

        Gets the date and time the resource image was last modified.

        Parameters:
        useDefault - if set to true uses the information from FileInfo as default value.
        Returns:
        The date and time the resource image was last modified.
      • dither

        public void dither(int ditheringMethod,
                           int bitsCount)

        Performs dithering on the current image.

        Parameters:
        ditheringMethod - The dithering method.
        bitsCount - The final bits count for dithering.
        Code example:

        The following example loads a raster image and performs threshold and floyd dithering using different palette depth.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Perform threshold dithering using 4-bit color palette which contains 16 colors.
            // The more bits specified the higher quality and the bigger size of the output image.
            // Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
            rasterImage.dither(com.aspose.imaging.DitheringMethod.ThresholdDithering, 4);
        
            rasterImage.save(dir + "sample.ThresholdDithering4.png");
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Perform floyd dithering using 1-bit color palette which contains only 2 colors - black and white.
            // The more bits specified the higher quality and the bigger size of the output image.
            // Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
            rasterImage.dither(com.aspose.imaging.DitheringMethod.FloydSteinbergDithering, 1);
        
            rasterImage.save(dir + "sample.FloydSteinbergDithering1.png");
        } finally {
            image.dispose();
        }
        

      • dither

        public abstract void dither(int ditheringMethod,
                                    int bitsCount,
                                    IColorPalette customPalette)

        Performs dithering on the current image.

        Parameters:
        ditheringMethod - The dithering method.
        bitsCount - The final bits count for dithering.
        customPalette - The custom palette for dithering.
      • getDefaultPixels

        public void getDefaultPixels(Rectangle rectangle,
                                     IPartialArgb32PixelLoader partialPixelLoader)

        Gets the default pixels array using partial pixel loader.

        Parameters:
        rectangle - The rectangle to get pixels for.
        partialPixelLoader - The partial pixel loader.
      • getDefaultRawData

        public void getDefaultRawData(Rectangle rectangle,
                                      IPartialRawDataLoader partialRawDataLoader,
                                      RawDataSettings rawDataSettings)

        Gets the default raw data array using partial pixel loader.

        Parameters:
        rectangle - The rectangle to get pixels for.
        partialRawDataLoader - The partial raw data loader.
        rawDataSettings - The raw data settings.
      • getDefaultArgb32Pixels

        public int[] getDefaultArgb32Pixels(Rectangle rectangle)

        Gets the default 32-bit ARGB pixels array.

        Parameters:
        rectangle - The rectangle to get pixels for.
        Returns:
        The default pixels array.
      • getDefaultRawData

        public byte[] getDefaultRawData(Rectangle rectangle,
                                        RawDataSettings rawDataSettings)

        Gets the default raw data array.

        Parameters:
        rectangle - The rectangle to get raw data for.
        rawDataSettings - The raw data settings.
        Returns:
        The default raw data array.
      • getArgb32Pixel

        public int getArgb32Pixel(int x,
                                  int y)

        Gets an image 32-bit ARGB pixel.

        Parameters:
        x - The pixel x location.
        y - The pixel y location.
        Returns:
        The 32-bit ARGB pixel for the specified location.
        Code example:

        The following example loads a raster image and obtains the color of an arbitrary pixel represented as a 32-bit integer value.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Get an integer representation of the color of the top-left pixel of the image.
            int color = rasterImage.getArgb32Pixel(0, 0);
        
            // To obtain the values of the individual color components, shift the color value by a corresponding number of bits
            int alpha = (color >> 24) & 0xff;
            int red = (color >> 16) & 0xff;
            int green = (color >> 8) & 0xff;
            int blue = (color >> 0) & 0xff;
        
            System.out.println("The color of the pixel(0,0) is A=" + alpha + ",R=" + red + ",G=" + green + ",B=" + blue);
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The color of the pixel(0,0) is A=255,R=0,G=0,B=0
        

      • getPixel

        public Color getPixel(int x,
                              int y)

        Gets an image pixel.

        Parameters:
        x - The pixel x location.
        y - The pixel y location.
        Returns:
        The pixel color for the specified location.
        Code example:

        The following example loads a raster image and obtains the color of an arbitrary pixel.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Get the color of the top-left pixel of the image.
            com.aspose.imaging.Color color = rasterImage.getPixel(0, 0);
        
            // Obtain the values of the individual color components
            int alpha = color.getA();
            int red = color.getR();
            int green = color.getG();
            int blue = color.getB();
        
            System.out.println("The color of the pixel(0,0) is A=" + alpha + ",R=" + red + ",G=" + green + ",B=" + blue);
        } finally {
            image.dispose();
        }
        

      • setArgb32Pixel

        public void setArgb32Pixel(int x,
                                   int y,
                                   int argb32Color)

        Sets an image 32-bit ARGB pixel for the specified position.

        Parameters:
        x - The pixel x location.
        y - The pixel y location.
        argb32Color - The 32-bit ARGB pixel for the specified position.
        Code example:

        The following example loads a raster image, and sets the color of an arbitrary pixel.


        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Sets the color of the top-left pixel.
            rasterImage.setArgb32Pixel(0, 0, com.aspose.imaging.Color.getAqua().toArgb());
        
            // Another way is to pass an instance of the com.aspose.imaging.Color directly
            rasterImage.setPixel(0, 0, com.aspose.imaging.Color.getAqua());
        } finally {
            image.dispose();
        }
        

      • setPixel

        public void setPixel(int x,
                             int y,
                             Color color)

        Sets an image pixel for the specified position.

        Parameters:
        x - The pixel x location.
        y - The pixel y location.
        color - The pixel color for the specified position.
        Code example:

        The following example loads a raster image, and sets the color of an arbitrary pixel.


        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Sets the color of the top-left pixel.
            rasterImage.setArgb32Pixel(0, 0, com.aspose.imaging.Color.getAqua().toArgb());
        
            // Another way is to pass an instance of the com.aspose.imaging.Color directly
            rasterImage.setPixel(0, 0, com.aspose.imaging.Color.getAqua());
        } finally {
            image.dispose();
        }
        

      • readScanLine

        public Color[] readScanLine(int scanLineIndex)

        Reads the whole scan line by the specified scan line index.

        Parameters:
        scanLineIndex - Zero based index of the scan line.
        Returns:
        The scan line pixel color values array.
      • readArgb32ScanLine

        public int[] readArgb32ScanLine(int scanLineIndex)

        Reads the whole scan line by the specified scan line index.

        Parameters:
        scanLineIndex - Zero based index of the scan line.
        Returns:
        The scan line 32-bit ARGB color values array.
      • writeScanLine

        public void writeScanLine(int scanLineIndex,
                                  Color[] pixels)

        Writes the whole scan line to the specified scan line index.

        Parameters:
        scanLineIndex - Zero based index of the scan line.
        pixels - The pixel colors array to write.
      • writeArgb32ScanLine

        public void writeArgb32ScanLine(int scanLineIndex,
                                        int[] argb32Pixels)

        Writes the whole scan line to the specified scan line index.

        Parameters:
        scanLineIndex - Zero based index of the scan line.
        argb32Pixels - The 32-bit ARGB colors array to write.
      • loadPartialArgb32Pixels

        public final void loadPartialArgb32Pixels(Rectangle rectangle,
                                                  IPartialArgb32PixelLoader partialPixelLoader)

        Loads 32-bit ARGB pixels partially by packs.

        Specified by:
        loadPartialArgb32Pixels in interface IRasterImageArgb32PixelLoader
        Parameters:
        rectangle - The desired rectangle.
        partialPixelLoader - The 32-bit ARGB pixel loader.
        Code example:

        The following example shows how to load and process pixels of a raster image using your own partial processor. For example, consider a problem of counting of fully transparent pixels of an image. In order to count transparent pixels using partial loading mechanism, a separate class TransparentArgb32PixelCounter implementing com.aspose.imaging.IPartialArgb32PixelLoader is introduced.


        
        // First, implement com.aspose.imaging.IPartialArgb32PixelLoader to count all fully transparent pixels.
        /** Counts the number of fully transparent pixels with alpha channel value of 0. */
        class TransparentArgb32PixelCounter implements com.aspose.imaging.IPartialArgb32PixelLoader {
            /**
             * The number of fully transparent pixels.
             */
            private int count;
        
            /**
             * Gets the number of fully transparent pixels.
             */
            public int getCount() {
                return this.count;
            }
        
            /**
             * <p>Processes the loaded pixels. This method is called back every time when a new portion of pixels is loaded.</p>                 *
             *
             * @param pixelsRectangle The pixels rectangle.
             * @param pixels          The 32-bit ARGB pixels.
             * @param start           The start pixels point.
             * @param end             The end pixels point.
             */
            public void process(com.aspose.imaging.Rectangle pixelsRectangle, int[] pixels, com.aspose.imaging.Point start, com.aspose.imaging.Point end) {
                for (int pixel : pixels) {
                    int alpha = (pixel >> 24) & 0xff;
                    if (alpha == 0) {
                        this.count++;
                    }
                }
            }
        }
        
        // Here is an example of using the counter.
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\alpha.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Create an instance of the com.aspose.imaging.IPartialArgb32PixelLoader and pass it to the com.aspose.imaging.RasterImage.LoadPartialArgb32Pixels
            TransparentArgb32PixelCounter counter = new TransparentArgb32PixelCounter();
        
            // Load pixels for the whole image. Any rectangular part of the image can be specified as the first parameter of the com.aspose.imaging.RasterImage.loadPartialArgb32Pixels method.
            rasterImage.loadPartialArgb32Pixels(rasterImage.getBounds(), counter);
        
            System.out.println("The number of fully transparent pixels is " + counter.getCount());
            System.out.println("The total number of pixels is " + (image.getWidth() * image.getHeight()));
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The number of fully transparent pixels is 55157
        // The total number of pixels is 120400
        

      • loadPartialPixels

        public void loadPartialPixels(Rectangle desiredRectangle,
                                      IPartialPixelLoader pixelLoader)

        Loads pixels partially by packs.

        Parameters:
        desiredRectangle - The desired rectangle.
        pixelLoader - The pixel loader.
        Code example:

        The following example shows how to load and process pixels of a raster image using your own partial processor. For example, consider a problem of counting of fully transparent pixels of an image. In order to count transparent using partial loading mechanism, a separate class TransparentPixelCounter implementing com.aspose.imaging.IPartialPixelLoader is introduced.


        
        // First, implement com.aspose.imaging.IPartialPixelLoader to count all fully transparent pixels.
        /** Counts the number of fully transparent pixels with alpha channel value of 0. */
        class TransparentPixelCounter implements com.aspose.imaging.IPartialPixelLoader {
            /**
             * The number of fully transparent pixels.
             */
            private int count;
        
            /**
             * Gets the number of fully transparent pixels.
             */
            public int getCount() {
                return this.count;
            }
        
            /**
             * <p>Processes the loaded pixels. This method is called back every time when a new portion of pixels is loaded.</p>
             *
             * @param pixelsRectangle The pixels rectangle.
             * @param pixels          The 32-bit ARGB pixels.
             * @param start           The start pixels point.
             * @param end             The end pixels point.
             */
            public void process(com.aspose.imaging.Rectangle pixelsRectangle, com.aspose.imaging.Color[] pixels, com.aspose.imaging.Point start, com.aspose.imaging.Point end) {
                for (com.aspose.imaging.Color pixel : pixels) {
                    if (pixel.getA() == 0) {
                        this.count++;
                    }
                }
            }
        }
        
        // Here is an example of using the counter.
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\alpha.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Create an instance of the com.aspose.imaging.IPartialPixelLoader and pass it to the com.aspose.imaging.RasterImage.loadPartialPixels
            TransparentPixelCounter counter = new TransparentPixelCounter();
        
            // Load pixels for the whole image. Any rectangular part of the image can be specified as the first parameter of the com.aspose.imaging.RasterImage.loadPartialPixels method.
            rasterImage.loadPartialPixels(rasterImage.getBounds(), counter);
        
            System.out.println("The number of fully transparent pixels is " + counter.getCount());
            System.out.println("The total number of pixels is " + (image.getWidth() * image.getHeight()));
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The number of fully transparent pixels is 55157
        // The total number of pixels is 120400
        

      • loadArgb32Pixels

        public int[] loadArgb32Pixels(Rectangle rectangle)

        Loads 32-bit ARGB pixels.

        Parameters:
        rectangle - The rectangle to load pixels from.
        Returns:
        The loaded 32-bit ARGB pixels array.
        Code example:

        The following example shows how to load and process pixels of a raster image. The pixels are represented as 32-bit integer values. For example, consider a problem of counting of fully transparent pixels of an image.


        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\alpha.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the com.aspose.imaging.RasterImage.loadArgb32Pixels method.
            int[] pixels = rasterImage.loadArgb32Pixels(rasterImage.getBounds());
        
            int count = 0;
            for (int pixel : pixels) {
                int alpha = (pixel >> 24) & 0xff;
                if (alpha == 0) {
                    count++;
                }
            }
        
            System.out.println("The number of fully transparent pixels is " + count);
            System.out.println("The total number of pixels is " + (image.getWidth() * image.getHeight()));
        } finally {
            image.dispose();
        }
        

      • loadArgb64Pixels

        public long[] loadArgb64Pixels(Rectangle rectangle)

        Loads 64-bit ARGB pixels.

        Parameters:
        rectangle - The rectangle to load pixels from.
        Returns:
        The loaded 64-bit ARGB pixels array.
        Code example:

        The following example shows how to load and process pixels of a raster image. The pixels are represented as 64-bit integer values. For example, consider a problem of counting of fully transparent pixels of an image.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\16rgba.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the com.aspose.imaging.RasterImage.loadArgb64Pixels method.
            // Note that the image itself must have 16 bits per sample, because com.aspose.imaging.RasterImage.loadArgb64Pixels doesn't work with 8 bit per sample.
            // In order to work with 8 bits per sample please use the good old com.aspose.imaging.RasterImage.loadArgb32Pixels method.
            long[] pixels = rasterImage.loadArgb64Pixels(rasterImage.getBounds());
        
            int count = 0;
            for (long pixel : pixels) {
                // Note that all color components including alpha are represented by 16-bit values, so their allowed values are in the range [0, 63535].
                long alpha = (pixel >> 48) & 0xffff;
                if (alpha == 0) {
                    count++;
                }
            }
        
            System.out.println("The number of fully transparent pixels is " + count);
            System.out.println("The total number of pixels is " + (image.getWidth() * image.getHeight()));
        } finally {
            image.dispose();
        }
        

      • loadPixels

        public Color[] loadPixels(Rectangle rectangle)

        Loads pixels.

        Parameters:
        rectangle - The rectangle to load pixels from.
        Returns:
        The loaded pixels array.
        Code example:

        The following example shows how to load and process pixels of a raster image. For example, consider a problem of counting of fully transparent pixels of an image.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\alpha.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the Aspose.Imaging.RasterImage.LoadPixels method.
            com.aspose.imaging.Color[] pixels = rasterImage.loadPixels(rasterImage.getBounds());
        
            int count = 0;
            for (com.aspose.imaging.Color pixel : pixels) {
                if (pixel.getA() == 0) {
                    count++;
                }
            }
        
            System.out.println("The number of fully transparent pixels is " + count);
            System.out.println("The total number of pixels is " + (image.getWidth() * image.getHeight()));
        } finally {
            image.dispose();
        }
        

      • loadCmykPixels

        @Deprecated
        public CmykColor[] loadCmykPixels(Rectangle rectangle)
        Deprecated. use instead loadCmyk32Pixels(Rectangle)

        Loads pixels in CMYK format. This method is deprecated. Please use more effective the loadCmyk32Pixels(Rectangle) method.

        Parameters:
        rectangle - The rectangle to load pixels from.
        Returns:
        The loaded CMYK pixels array.
      • loadCmyk32Pixels

        public int[] loadCmyk32Pixels(Rectangle rectangle)

        Loads pixels in CMYK format.

        Parameters:
        rectangle - The rectangle to load pixels from.
        Returns:
        The loaded CMYK pixels presentes as 32-bit inateger values.
      • loadRawData

        public void loadRawData(Rectangle rectangle,
                                RawDataSettings rawDataSettings,
                                IPartialRawDataLoader rawDataLoader)

        Loads raw image data using the partial processing mechanism.

        Specified by:
        loadRawData in interface IRasterImageRawDataLoader
        Parameters:
        rectangle - The desired rectangular area of the image to load data from.
        rawDataSettings - The raw data settings.
        rawDataLoader - The raw data loader.
        Code example:

        The following example shows how to extract pixels from the raw image data using RawDataSettings. For example, consider a problem of counting of fully transparent pixels of an image.


        
        // First, implement a counter. In case of raw data, the counter may look like this:
        /** Counts the number of fully transparent pixels with alpha channel value of 0. */
        class TransparentPixelRawDataCounter implements com.aspose.imaging.IPartialRawDataLoader {
            /**
             * The number of fully transparent pixels.
             */
            private int count;
        
            /**
             * The raw data settings of the loaded image.
             */
            private com.aspose.imaging.RawDataSettings rawDataSettings;
        
            /**
             * Gets the number of fully transparent pixels.
             */
            public int getCount() {
                return this.count;
            }
        
            /**
             * <p>Initializes a new instance of the <see TransparentPixelRawDataCounter /> class.</p>
             *
             * @param settings The raw data settings allow to extract color components from raw data.
             */
            public TransparentPixelRawDataCounter(com.aspose.imaging.RawDataSettings settings) {
                this.rawDataSettings = settings;
                this.count = 0;
            }
        
            /**
             * <p>Processes the loaded raw data. This method is called back every time when a new portion of raw data is loaded.</p>
             *
             * @param dataRectangle The raw data rectangle.
             * @param data          The raw data.
             * @param start         The start data point.
             * @param end           The end data point.
             */
            public void process(com.aspose.imaging.Rectangle dataRectangle, byte[] data, com.aspose.imaging.Point start, com.aspose.imaging.Point end)// throws java.lang.Exception
            {
                int[] channelBits = this.rawDataSettings.getPixelDataFormat().getChannelBits();
        
                // Only simple formats are considered here to simplify the code.
                // Let's consider only images with 8 bits per sample.
                for (int i = 0; i < channelBits.length; i++) {
                    if (channelBits[i] != 8) {
                        throw new java.lang.UnsupportedOperationException();
                    }
                }
        
                switch (this.rawDataSettings.getPixelDataFormat().getPixelFormat()) {
                    case com.aspose.imaging.PixelFormat.Rgb:
                    case com.aspose.imaging.PixelFormat.Bgr: {
                        if (channelBits.length == 4) {
                            // ARGB
                            for (int i = 0; i < data.length; i += 4) {
                                // The alpha channel is stored last, after the color components.
                                if (data[i + 3] == 0) {
                                    this.count++;
                                }
                            }
                        }
                    }
                    break;
        
                    case com.aspose.imaging.PixelFormat.Grayscale: {
                        if (channelBits.length == 2) {
                            // Grayscale Alpha
                            for (int i = 0; i < data.length; i += 2) {
                                // The alpha channel is stored last, after the color components.
                                if (data[i + 1] == 0) {
                                    this.count++;
                                }
                            }
                        }
                    }
                    break;
        
                    default:
                        throw new java.lang.IllegalArgumentException("PixelFormat");
                }
            }
        
            /**
             * <p>Processes the loaded raw data. This method is called back every time when a new portion of raw data is loaded.</p>                 *
             *
             * @param dataRectangle The raw data rectangle.
             * @param data          The raw data.
             * @param start         The start data point.
             * @param end           The end data point.
             * @param loadOptions   The load options.
             */
            public void process(com.aspose.imaging.Rectangle dataRectangle, byte[] data, com.aspose.imaging.Point start, com.aspose.imaging.Point end, com.aspose.imaging.LoadOptions loadOptions) {
                this.process(dataRectangle, data, start, end);
            }
        }
        
        // Here is the main example of using the counter
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\alpha.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
            com.aspose.imaging.RawDataSettings settings = rasterImage.getRawDataSettings();
        
            TransparentPixelRawDataCounter rawDataLoader = new TransparentPixelRawDataCounter(settings);
        
            // Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the Aspose.Imaging.RasterImage.LoadRawData method.
            rasterImage.loadRawData(rasterImage.getBounds(), settings, rawDataLoader);
        
            System.out.println("The number of fully transparent pixels is " + rawDataLoader.getCount());
            System.out.println("The total number of pixels is " + (image.getWidth() * image.getHeight()));
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The number of fully transparent pixels is 55157
        // The total number of pixels is 120400
        

      • loadRawData

        public void loadRawData(Rectangle rectangle,
                                Rectangle destImageBounds,
                                RawDataSettings rawDataSettings,
                                IPartialRawDataLoader rawDataLoader)

        Loads raw data.

        Parameters:
        rectangle - The rectangle to load raw data from.
        destImageBounds - The dest image bounds.
        rawDataSettings - The raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
        rawDataLoader - The raw data loader.
      • saveRawData

        public void saveRawData(byte[] data,
                                int dataOffset,
                                Rectangle rectangle,
                                RawDataSettings rawDataSettings)

        Saves the raw data.

        Parameters:
        data - The raw data.
        dataOffset - The starting raw data offset.
        rectangle - The raw data rectangle.
        rawDataSettings - The raw data settings the data is in.
      • saveArgb32Pixels

        public void saveArgb32Pixels(Rectangle rectangle,
                                     int[] pixels)

        Saves the 32-bit ARGB pixels.

        Specified by:
        saveArgb32Pixels in interface com.aspose.imaging_internal.IPixelsSaver
        Parameters:
        rectangle - The rectangle to save pixels to.
        pixels - The 32-bit ARGB pixels array.
        Code example:

        The following example fills the central area of a raster image with black pixels using the com.aspose.imaging.RasterImage.saveArgb32Pixels method.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // The black square
            int[] pixels = new int[(rasterImage.getWidth() / 2) * (rasterImage.getHeight() / 2)];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getBlack().toArgb();
            }
        
            // Draw the black square at the center of the image.
            com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle(rasterImage.getWidth() / 4, rasterImage.getHeight() / 4, rasterImage.getWidth() / 2, rasterImage.getHeight() / 2);
            rasterImage.saveArgb32Pixels(area, pixels);
        
            rasterImage.save(dir + "sample.SaveArgb32Pixels.png");
        } finally {
            image.dispose();
        }
        

      • savePixels

        public void savePixels(Rectangle rectangle,
                               Color[] pixels)

        Saves the pixels.

        Parameters:
        rectangle - The rectangle to save pixels to.
        pixels - The pixels array.
        Code example:

        The following example fills the central area of a raster image with black pixels using the com.aspose.imaging.RasterImage.savePixels method.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // The black square
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[(rasterImage.getWidth() / 2) * (rasterImage.getHeight() / 2)];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getBlack();
            }
        
            // Draw the black square at the center of the image.
            com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle(rasterImage.getWidth() / 4, rasterImage.getHeight() / 4, rasterImage.getWidth() / 2, rasterImage.getHeight() / 2);
            rasterImage.savePixels(area, pixels);
        
            rasterImage.save(dir + "sample.SavePixels.png");
        } finally {
            image.dispose();
        }
        

      • toBitmap

        public BufferedImage toBitmap()

        Converts raster image to the bitmap.

        Returns:
        The bitmap
        Code example:

        The following example converts a BMP image to a native Java bitmap.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
            java.awt.image.BufferedImage bitmap = bmpImage.toBitmap();
        
            // Process the native Java bitmap.
        } finally {
            image.dispose();
        }
        

      • saveCmykPixels

        @Deprecated
        public void saveCmykPixels(Rectangle rectangle,
                                                CmykColor[] pixels)
        Deprecated. use instead saveCmyk32Pixels(Rectangle, int[])

        Saves the pixels. This method is deprecated. Please use more effective the saveCmyk32Pixels(Rectangle, int[]) method.

        Parameters:
        rectangle - The rectangle to save pixels to.
        pixels - The CMYK pixels array.
      • saveCmyk32Pixels

        public void saveCmyk32Pixels(Rectangle rectangle,
                                     int[] pixels)

        Saves the pixels.

        Parameters:
        rectangle - The rectangle to save pixels to.
        pixels - The CMYK pixels presented as the 32-bit integer values.
        Code example:

        The following example fills the central area of a raster image with black pixels using the com.aspose.imaging.RasterImage.saveCmyk32Pixels method.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Get an integer representation of black in the CMYK color space.
            int blackCmyk = com.aspose.imaging.CmykColorHelper.toCmyk(com.aspose.imaging.Color.getBlack());
        
            // The black square.
            int[] pixels = new int[(rasterImage.getWidth() / 2) * (rasterImage.getHeight() / 2)];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = blackCmyk;
            }
        
            // Draw the black square at the center of the image.
            com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle(rasterImage.getWidth() / 4, rasterImage.getHeight() / 4, rasterImage.getWidth() / 2, rasterImage.getHeight() / 2);
            rasterImage.saveCmyk32Pixels(area, pixels);
        
            rasterImage.save(dir + "sample.SaveCmyk32Pixels.png");
        } finally {
            image.dispose();
        }
        

      • setResolution

        public void setResolution(double dpiX,
                                  double dpiY)

        Sets the resolution for this RasterImage.

        Parameters:
        dpiX - The horizontal resolution, in dots per inch, of the RasterImage.
        dpiY - The vertical resolution, in dots per inch, of the RasterImage.
        Code example:

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


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.jpg");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Get horizontal and vertical resolution of the image
            double horizontalResolution = rasterImage.getHorizontalResolution();
            double verticalResolution = rasterImage.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");
                rasterImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + rasterImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + rasterImage.getVerticalResolution());
            }
        
            // 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
        } finally {
            image.dispose();
        }
        

      • setPalette

        public void setPalette(IColorPalette palette,
                               boolean updateColors)

        Sets the image palette.

        Specified by:
        setPalette in class Image
        Parameters:
        palette - The palette to set.
        updateColors - if set to true colors will be updated according to the new palette; otherwise color indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no corresponding palette entries.
      • resize

        public void resize(int newWidth,
                           int newHeight,
                           int resizeType)

        Resizes the image.

        Specified by:
        resize in class Image
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
        Code example:

        This example loads a raster image and resizes it using various resizing methods.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "sample.gif");
        try {
            // Scale up by 2 times using Nearest Neighbour resampling.
            image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
            image.save(dir + "upsample.nearestneighbour.gif");
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "sample.gif");
        try {
            // Scale down by 2 times using Nearest Neighbour resampling.
            image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
            image.save(dir + "downsample.nearestneighbour.gif");
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "sample.gif");
        try {
            // Scale up by 2 times using Bilinear resampling.
            image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
            image.save(dir + "upsample.bilinear.gif");
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "sample.gif");
        try {
            // Scale down by 2 times using Bilinear resampling.
            image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
            image.save(dir + "downsample.bilinear.gif");
        } finally {
            image.dispose();
        }
        

      • resize

        public void resize(int newWidth,
                           int newHeight,
                           ImageResizeSettings settings)

        Resizes the image with extended options.

        Specified by:
        resize in class Image
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        settings - The resize settings.
        Code example:

        This example loads a raster image and resizes it using various resizing settings.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.ImageResizeSettings resizeSettings = new com.aspose.imaging.ImageResizeSettings();
        
        // The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
        resizeSettings.setMode(com.aspose.imaging.ResizeType.AdaptiveResample);
        
        // The small rectangular filter
        resizeSettings.setFilterType(com.aspose.imaging.ImageFilterType.SmallRectangular);
        
        // The number of colors in the palette.
        resizeSettings.setEntriesCount(256);
        
        // The color quantization is not used
        resizeSettings.setColorQuantizationMethod(com.aspose.imaging.ColorQuantizationMethod.None);
        
        // The euclidian method
        resizeSettings.setColorCompareMethod(com.aspose.imaging.ColorCompareMethod.Euclidian);
        
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "sample.gif");
        try {
            // Scale down by 2 times using adaptive resampling.
            image.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings);
            image.save(dir + "downsample.adaptive.gif");
        } finally {
            image.dispose();
        }
        

      • crop

        public void crop(Rectangle rectangle)

        Crops the specified rectangle.

        Parameters:
        rectangle - The rectangle.
        Code example:

        The following example crops a raster image. The cropping area is be specified via com.aspose.imaging.Rectangle.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Crop the image. The cropping area is the rectangular central area of the image.
            com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle(rasterImage.getWidth() / 4, rasterImage.getHeight() / 4, rasterImage.getWidth() / 2, rasterImage.getHeight() / 2);
            rasterImage.crop(area);
        
            // Save the cropped image to PNG
            rasterImage.save(dir + "sample.Crop.png");
        } finally {
            image.dispose();
        }
        

      • binarizeFixed

        public void binarizeFixed(byte threshold)

        Binarization of an image with predefined threshold

        Parameters:
        threshold - Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.
        Code example:

        The following example binarizes a raster image with the predefined threshold. Binarized images contain only 2 colors - black and white.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Binarize the image with a threshold value of 127.
            // If a corresponding gray value of a pixel is greater than 127, a value of 255 will be assigned to it, 0 otherwise.
            rasterImage.binarizeFixed((byte) 127);
            rasterImage.save(dir + "sample.BinarizeFixed.png");
        } finally {
            image.dispose();
        }
        

      • binarizeOtsu

        public void binarizeOtsu()

        Binarization of an image with Otsu thresholding

        Code example:

        The following example binarizes a raster image with Otsu thresholding. Binarized images contain only 2 colors - black and white.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Binarize the image with Otsu thresholding.
            rasterImage.binarizeOtsu();
            rasterImage.save(dir + "sample.BinarizeOtsu.png");
        } finally {
            image.dispose();
        }
        

      • binarizeBradley

        public void binarizeBradley(double brightnessDifference)

        Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding

        Parameters:
        brightnessDifference - The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
      • binarizeBradley

        public void binarizeBradley(double brightnessDifference,
                                    int windowSize)

        Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding

        Parameters:
        brightnessDifference - The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
        windowSize - The size of s x s window of pixels centered around this pixel
        Code example:

        The following example binarizes a raster image with Bradley's adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Binarize the image with a brightness difference of 5. The brightness is a difference between a pixel and the average of an 10 x 10 window of pixels centered around this pixel.
            rasterImage.binarizeBradley(5, 10);
            rasterImage.save(dir + "sample.BinarizeBradley5_10x10.png");
        } finally {
            image.dispose();
        }
        

      • grayscale

        public void grayscale()

        Transformation of an image to its grayscale representation

        Code example:

        The following example transforms a colored raster image to its grayscale representation. Grayscale images are composed exclusively of shades of gray and carry only intensity information.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            rasterImage.grayscale();
            rasterImage.save(dir + "sample.Grayscale.png");
        } finally {
            image.dispose();
        }
        

      • adjustBrightness

        public void adjustBrightness(int brightness)

        Adjust of a brightness for image.

        Parameters:
        brightness - Brightness value.
        Code example:

        The following example performs brightness correction of an image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Set the brightness value. The accepted values of brightness are in the range [-255, 255].
            rasterImage.adjustBrightness(50);
            rasterImage.save(dir + "sample.AdjustBrightness.png");
        } finally {
            image.dispose();
        }
        

      • adjustContrast

        public void adjustContrast(float contrast)

        Image contrasting

        Parameters:
        contrast - Contrast value (in range [-100; 100])
        Code example:

        The following example performs contrast correction of an image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Set the contrast value. The accepted values of contrast are in the range [-100f, 100f].
            rasterImage.adjustContrast(50);
            rasterImage.save(dir + "sample.AdjustContrast.png");
        } finally {
            image.dispose();
        }
        

      • adjustGamma

        public void adjustGamma(float gammaRed,
                                float gammaGreen,
                                float gammaBlue)

        Gamma-correction of an image.

        Parameters:
        gammaRed - Gamma for red channel coefficient
        gammaGreen - Gamma for green channel coefficient
        gammaBlue - Gamma for blue channel coefficient
        Code example:

        The following example performs gamma-correction of an image applying different coefficients for color components.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Set individual gamma coefficients for red, green and blue channels.
            rasterImage.adjustGamma(1.5f, 2.5f, 3.5f);
            rasterImage.save(dir + "sample.AdjustGamma.png");
        } finally {
            image.dispose();
        }
        

      • adjustGamma

        public void adjustGamma(float gamma)

        Gamma-correction of an image.

        Parameters:
        gamma - Gamma for red, green and blue channels coefficient
        Code example:

        The following example performs gamma-correction of an image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Set gamma coefficient for red, green and blue channels.
            rasterImage.adjustGamma(2.5f);
            rasterImage.save(dir + "sample.AdjustGamma.png");
        } finally {
            image.dispose();
        }
        

      • crop

        public void crop(int leftShift,
                         int rightShift,
                         int topShift,
                         int bottomShift)

        Crop image with shifts.

        Parameters:
        leftShift - The left shift.
        rightShift - The right shift.
        topShift - The top shift.
        bottomShift - The bottom shift.
        Code example:

        The following example crops a raster image. The cropping area is specified via Left, Top, Right, Bottom margins.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Crop again. Set a margin of 10% of the image size.
            int horizontalMargin = rasterImage.getWidth() / 10;
            int verticalMargin = rasterImage.getHeight() / 10;
            rasterImage.crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);
        
            // Save the cropped image to PNG.
            rasterImage.save(dir + "sample.Crop.png");
        } finally {
            image.dispose();
        }
        

      • rotate

        public void rotate(float angle,
                           boolean resizeProportionally,
                           Color backgroundColor)

        Rotate image around the center.

        Parameters:
        angle - The rotate angle in degrees. Positive values will rotate clockwise.
        resizeProportionally - if set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
        backgroundColor - Color of the background.
        Throws:
        com.aspose.ms.System.NotImplementedException
      • rotate

        public void rotate(float angle)

        Rotate image around the center.

        Parameters:
        angle - The rotate angle in degrees. Positive values will rotate clockwise.
      • getSkewAngle

        public final float getSkewAngle()

        Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning.

        Returns:
        The skew angle, in degrees.
      • normalizeAngle

        public void normalizeAngle(boolean resizeProportionally,
                                   Color backgroundColor)

        Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses RasterImage.getSkewAngle() and RasterImage.rotate(float, boolean, Color) methods.

        Parameters:
        resizeProportionally - if set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
        backgroundColor - Color of the background.
        Code example:

        Skew is an artifact that might appear during document scanning process when the text/images of the document get rotated at a slight angle. It can have various causes but the most common is that the paper get misplaced during a scan. Therefore, deskew is the process of detecting and fixing this issue on scanned files(i.e. bitmap) so deskewed documents will have the text/images correctly and horizontally adjusted.


        String dir = "c:\\aspose.imaging\\issues\\java\\1461\\";
        
        String inputFilePath = dir + "skewed.png";
        String outputFilePath = dir + "skewed.out.png";
        
        // Get rid of the skewed scan with default parameters
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(inputFilePath);
        try {
            // Deskew
            image.normalizeAngle(false /*do not resize*/, com.aspose.imaging.Color.getLightGray() /*background color*/);
            image.save(outputFilePath);
        } finally {
            image.close();
        }
        

      • filter

        public void filter(Rectangle rectangle,
                           FilterOptionsBase options)

        Filters the specified rectangle.

        Parameters:
        rectangle - The rectangle.
        options - The options.
        Code example:

        The following example applies various types of filters to a raster image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Apply a median filter with a rectangle size of 5 to the entire image.
            rasterImage.filter(rasterImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(5));
            rasterImage.save(dir + "sample.MedianFilter.png");
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
            rasterImage.filter(rasterImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(5));
            rasterImage.save(dir + "sample.BilateralSmoothingFilter.png");
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
            rasterImage.filter(rasterImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions(5, 4.0));
            rasterImage.save(dir + "sample.GaussianBlurFilter.png");
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
            rasterImage.filter(rasterImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussWienerFilterOptions(5, 4.0));
            rasterImage.save(dir + "sample.GaussWienerFilter.png");
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
            rasterImage.filter(rasterImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MotionWienerFilterOptions(10, 1.0, 90.0));
            rasterImage.save(dir + "sample.MotionWienerFilter.png");
        } finally {
            image.dispose();
        }
        
        image = com.aspose.imaging.Image.load(dir + "sample.png");
        try {
            com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
        
            // Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
            rasterImage.filter(rasterImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions(5, 4.0));
            rasterImage.save(dir + "sample.SharpenFilter.png");
        } finally {
            image.dispose();
        }
        

      • replaceColor

        public void replaceColor(Color oldColor,
                                 byte oldColorDiff,
                                 Color newColor)

        Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

        Parameters:
        oldColor - Old color to be replaced.
        oldColorDiff - Allowed difference in old color to be able to widen replaced color tone.
        newColor - New color to replace old color with.
      • replaceColor

        public void replaceColor(int oldColorArgb,
                                 byte oldColorDiff,
                                 int newColorArgb)

        Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

        Parameters:
        oldColorArgb - Old color ARGB value to be replaced.
        oldColorDiff - Allowed difference in old color to be able to widen replaced color tone.
        newColorArgb - New color ARGB value to replace old color with.
      • replaceNonTransparentColors

        public void replaceNonTransparentColors(Color newColor)

        Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.

        Parameters:
        newColor - New color to replace non transparent colors with.
      • replaceNonTransparentColors

        public void replaceNonTransparentColors(int newColorArgb)

        Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.

        Parameters:
        newColorArgb - New color ARGB value to replace non transparent colors with.