RasterImage

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter, com.aspose.imaging.Image

All Implemented Interfaces: com.aspose.imaging.IRasterImageArgb32PixelLoader, com.aspose.internal.IPixelsSaver, com.aspose.imaging.xmp.IHasXmpData

public abstract class RasterImage extends Image implements IRasterImageArgb32PixelLoader, IPixelsSaver, IHasXmpData

Represents a raster image supporting raster graphics operations.

Methods

MethodDescription
getPremultiplyComponents()Gets or sets a value indicating whether the image components must be premultiplied.
setPremultiplyComponents(boolean value)Gets or sets a value indicating whether the image components must be premultiplied.
getUseRawData()Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
setUseRawData(boolean value)Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
getUpdateXmpData()Gets or sets a value indicating whether to update the XMP metadata.
setUpdateXmpData(boolean value)Gets or sets a value indicating whether to update the XMP metadata.
getXmpData()Gets or sets the XMP metadata.
setXmpData(XmpPacketWrapper value)Gets or sets the XMP metadata.
getRawIndexedColorConverter()Gets or sets the indexed color converter
setRawIndexedColorConverter(IIndexedColorConverter value)Gets or sets the indexed color converter
getRawCustomColorConverter()Gets or sets the custom color converter
setRawCustomColorConverter(IColorConverter value)Gets or sets the custom color converter
getRawFallbackIndex()Gets or sets the fallback index to use when palette index is out of bounds
setRawFallbackIndex(int value)Gets or sets the fallback index to use when palette index is out of bounds
getRawDataSettings()
isUsePalette()Gets a value indicating whether the image palette is used.
getRawDataFormat()Gets the raw data format.
getRawLineSize()Gets the raw line size in bytes.
isRawDataAvailable()Gets a value indicating whether raw data loading is available.
getHorizontalResolution()Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.
setHorizontalResolution(double value)Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.
getVerticalResolution()Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.
setVerticalResolution(double value)Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.
hasTransparentColor()Gets a value indicating whether image has transparent color.
hasAlpha()Gets a value indicating whether this instance has alpha.
getTransparentColor()Gets the image transparent color.
setTransparentColor(boolean value)Gets a value indicating whether image has transparent color.
setTransparentColor(Color value)Gets the image transparent color.
getImageOpacity()Gets opacity of this image.
removeMetadata()Removes this image instance metadata by setting this IHasXmpData.XmpData(IHasXmpData.getXmpData/IHasXmpData.setXmpData(XmpPacketWrapper)) value to null.
getModifyDate(boolean useDefault)Retrieves the date and time when the resource image underwent its latest modification.
dither(int ditheringMethod, int bitsCount)Performs dithering on the current image.
dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)Performs dithering on the current image.
getDefaultPixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)Gets the default pixels array using partial pixel loader.
getDefaultRawData(Rectangle rectangle, IPartialRawDataLoader partialRawDataLoader, RawDataSettings rawDataSettings)Gets the default raw data array using partial pixel loader.
getDefaultArgb32Pixels(Rectangle rectangle)Gets the default 32-bit ARGB pixels array.
getDefaultRawData(Rectangle rectangle, RawDataSettings rawDataSettings)Gets the default raw data array.
getArgb32Pixel(int x, int y)Gets an image 32-bit ARGB pixel.
getPixel(int x, int y)Gets an image pixel.
setArgb32Pixel(int x, int y, int argb32Color)Sets an image 32-bit ARGB pixel for the specified position.
setPixel(int x, int y, Color color)Sets an image pixel for the specified position.
readScanLine(int scanLineIndex)Reads the whole scan line by the specified scan line index.
readArgb32ScanLine(int scanLineIndex)Reads the whole scan line by the specified scan line index.
writeScanLine(int scanLineIndex, Color[] pixels)Writes the whole scan line to the specified scan line index.
writeArgb32ScanLine(int scanLineIndex, int[] argb32Pixels)Writes the whole scan line to the specified scan line index.
loadPartialArgb32Pixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)Loads 32-bit ARGB pixels partially by packs.
loadPartialPixels(Rectangle desiredRectangle, IPartialPixelLoader pixelLoader)Loads pixels partially by packs.
loadArgb32Pixels(Rectangle rectangle)Loads 32-bit ARGB pixels.
loadArgb64Pixels(Rectangle rectangle)Loads 64-bit ARGB pixels.
loadPartialArgb64Pixels(Rectangle rectangle, IPartialArgb64PixelLoader partialPixelLoader)Loads 64-bit ARGB pixels partially by packs.
loadPixels(Rectangle rectangle)Loads pixels.
loadCmykPixels(Rectangle rectangle)Loads pixels in CMYK format.
loadCmyk32Pixels(Rectangle rectangle)Loads pixels in CMYK format.
loadRawData(Rectangle rectangle, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)Loads raw image data using the partial processing mechanism.
loadRawData(Rectangle rectangle, Rectangle dstImageBounds, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)Loads raw data.
saveRawData(byte[] data, int dataOffset, Rectangle rectangle, RawDataSettings rawDataSettings)Saves the raw data.
saveArgb32Pixels(Rectangle rectangle, int[] pixels)Saves the 32-bit ARGB pixels.
savePixels(Rectangle rectangle, Color[] pixels)Saves the pixels.
toBitmap()Converts raster image to the bitmap.
saveCmykPixels(Rectangle rectangle, CmykColor[] pixels)Saves the pixels.
saveCmyk32Pixels(Rectangle rectangle, int[] pixels)Saves the pixels.
setResolution(double dpiX, double dpiY)Sets the resolution for this RasterImage.
setPalette(IColorPalette palette, boolean updateColors)Sets the image palette.
resize(int newWidth, int newHeight, ImageResizeSettings settings)Resizes the image with extended options.
rotate(float angle, boolean resizeProportionally, Color backgroundColor)Rotate image around the center.
rotate(float angle)Rotate image around the center.
binarizeFixed(byte threshold)Binarization of an image with predefined threshold
binarizeOtsu()Binarization of an image with Otsu thresholding
binarizeBradley(double brightnessDifference)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
binarizeBradley(double brightnessDifference, int windowSize)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
blend(Point origin, RasterImage overlay, Rectangle overlayArea)Blends this image instance with the overlay image.
blend(Point origin, RasterImage overlay, Rectangle overlayArea, byte overlayAlpha)Blends this image instance with the overlay image.
blend(Point origin, RasterImage overlay)Blends this image instance with the overlay with alpha == 255.
blend(Point origin, RasterImage overlay, byte overlayAlpha)Blends this image instance with the overlay.
grayscale()Transformation of an image to its grayscale representation
adjustBrightness(int brightness)Adjust of a brightness for image.
adjustContrast(float contrast)Image contrasting
adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)Gamma-correction of an image.
adjustGamma(float gamma)Gamma-correction of an image.
getSkewAngle()Gets the skew angle.
normalizeAngle()Normalizes the angle.
normalizeAngle(boolean resizeProportionally, Color backgroundColor)Normalizes the angle.
filter(Rectangle rectangle, FilterOptionsBase options)Filters the specified rectangle.
replaceColor(Color oldColor, byte oldColorDiff, Color newColor)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
replaceColor(int oldColorArgb, byte oldColorDiff, int newColorArgb)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
replaceNonTransparentColors(Color newColor)Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.
replaceNonTransparentColors(int newColorArgb)Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.

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

getPremultiplyComponents()

public boolean getPremultiplyComponents()

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

Returns: boolean - true if the image components must be premultiplied; otherwise, false.

setPremultiplyComponents(boolean value)

public void setPremultiplyComponents(boolean value)

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

Parameters:

ParameterTypeDescription
valuebooleantrue if the image components must be premultiplied; otherwise, false.

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: boolean - true if use raw data loading when the raw data loading is available.; otherwise, false.

setUseRawData(boolean value)

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:

ParameterTypeDescription
valuebooleantrue 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: boolean - true if update the XMP metadata; otherwise, false.

setUpdateXmpData(boolean value)

public void setUpdateXmpData(boolean value)

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

Parameters:

ParameterTypeDescription
valuebooleantrue if update the XMP metadata; otherwise, false.

getXmpData()

public XmpPacketWrapper getXmpData()

Gets or sets the XMP metadata.

Returns: XmpPacketWrapper - The XMP metadata.

setXmpData(XmpPacketWrapper value)

public void setXmpData(XmpPacketWrapper value)

Gets or sets the XMP metadata.

Parameters:

ParameterTypeDescription
valueXmpPacketWrapperThe XMP metadata.

getRawIndexedColorConverter()

public IIndexedColorConverter getRawIndexedColorConverter()

Gets or sets the indexed color converter

Returns: IIndexedColorConverter - The indexed color converter

setRawIndexedColorConverter(IIndexedColorConverter value)

public void setRawIndexedColorConverter(IIndexedColorConverter value)

Gets or sets the indexed color converter

Parameters:

ParameterTypeDescription
valueIIndexedColorConverterThe indexed color converter

getRawCustomColorConverter()

public IColorConverter getRawCustomColorConverter()

Gets or sets the custom color converter

Returns: IColorConverter - The custom color converter

setRawCustomColorConverter(IColorConverter value)

public void setRawCustomColorConverter(IColorConverter value)

Gets or sets the custom color converter

Parameters:

ParameterTypeDescription
valueIColorConverterThe custom color converter

getRawFallbackIndex()

public int getRawFallbackIndex()

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

Returns: int - The fallback index to use when palette index is out of bounds

setRawFallbackIndex(int value)

public void setRawFallbackIndex(int value)

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

Parameters:

ParameterTypeDescription
valueintThe fallback index to use when palette index is out of bounds

getRawDataSettings()

public RawDataSettings getRawDataSettings()

Gets the current raw data settings. Note when using these settings the data loads without conversion.

Returns: RawDataSettings

isUsePalette()

public boolean isUsePalette()

Gets a value indicating whether the image palette is used.

Value: true if the palette is used in the image; otherwise, false.

Returns: boolean - a value indicating whether the image palette is used.

getRawDataFormat()

public PixelDataFormat getRawDataFormat()

Gets the raw data format.

Returns: PixelDataFormat - The raw data format.

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: int - The raw line size in bytes.

isRawDataAvailable()

public boolean isRawDataAvailable()

Gets a value indicating whether raw data loading is available.

Returns: boolean - 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: double - 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.

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(double value)

public void setHorizontalResolution(double value)

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

Parameters:

ParameterTypeDescription
valuedoubleThe 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: double - 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.

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(double value)

public void setVerticalResolution(double value)

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

Parameters:

ParameterTypeDescription
valuedoubleThe 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.

Returns: boolean

hasAlpha()

public boolean hasAlpha()

Gets a value indicating whether this instance has alpha.

Returns: boolean - true if this instance has alpha; otherwise, false.

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.

Returns: Color

setTransparentColor(boolean value)

public void setTransparentColor(boolean value)

Gets a value indicating whether image has transparent color.

Parameters:

ParameterTypeDescription
valueboolean

setTransparentColor(Color value)

public void setTransparentColor(Color value)

Gets the image transparent color.

Parameters:

ParameterTypeDescription
valueColor

getImageOpacity()

public float getImageOpacity()

Gets opacity of this image.

Returns: float - The opacity value between 0.0 (fully transparent) and 1.0 (fully opaque).

removeMetadata()

public void removeMetadata()

Removes this image instance metadata by setting this IHasXmpData.XmpData(IHasXmpData.getXmpData/IHasXmpData.setXmpData(XmpPacketWrapper)) value to null.

getModifyDate(boolean useDefault)

public Date getModifyDate(boolean useDefault)

Retrieves the date and time when the resource image underwent its latest modification. This method provides valuable metadata, enabling users to track and manage updates to the image file effectively. By accessing this information, users can ensure the integrity and currency of their image assets, facilitating informed decision-making regarding image usage and maintenance.

Parameters:

ParameterTypeDescription
useDefaultbooleanif set to true uses the information from FileInfo as default value.

Returns: java.util.Date - The date and time the resource image was last modified.

dither(int ditheringMethod, int bitsCount)

public void dither(int ditheringMethod, int bitsCount)

Performs dithering on the current image.

Parameters:

ParameterTypeDescription
ditheringMethodintThe dithering method.
bitsCountintThe final bits count for dithering.

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(int ditheringMethod, int bitsCount, IColorPalette customPalette)

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

Performs dithering on the current image.

Parameters:

ParameterTypeDescription
ditheringMethodintThe dithering method.
bitsCountintThe final bits count for dithering.
customPaletteIColorPaletteThe custom palette for dithering.

getDefaultPixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)

public void getDefaultPixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)

Gets the default pixels array using partial pixel loader.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get pixels for.
partialPixelLoaderIPartialArgb32PixelLoaderThe partial pixel loader.

getDefaultRawData(Rectangle rectangle, IPartialRawDataLoader partialRawDataLoader, RawDataSettings rawDataSettings)

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

Gets the default raw data array using partial pixel loader.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get pixels for.
partialRawDataLoaderIPartialRawDataLoaderThe partial raw data loader.
rawDataSettingsRawDataSettingsThe raw data settings.

getDefaultArgb32Pixels(Rectangle rectangle)

public int[] getDefaultArgb32Pixels(Rectangle rectangle)

Gets the default 32-bit ARGB pixels array.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get pixels for.

Returns: int[] - The default pixels array.

getDefaultRawData(Rectangle rectangle, RawDataSettings rawDataSettings)

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

Gets the default raw data array.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get raw data for.
rawDataSettingsRawDataSettingsThe raw data settings.

Returns: byte[] - The default raw data array.

getArgb32Pixel(int x, int y)

public int getArgb32Pixel(int x, int y)

Gets an image 32-bit ARGB pixel.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.

Returns: int - The 32-bit ARGB pixel for the specified location.

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(int x, int y)

public Color getPixel(int x, int y)

Gets an image pixel.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.

Returns: Color - The pixel color for the specified location.

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(int x, int y, int argb32Color)

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

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

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.
argb32ColorintThe 32-bit ARGB pixel for the specified position.

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(int x, int y, Color color)

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

Sets an image pixel for the specified position.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.
colorColorThe pixel color for the specified position.

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(int scanLineIndex)

public Color[] readScanLine(int scanLineIndex)

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

Parameters:

ParameterTypeDescription
scanLineIndexintZero based index of the scan line.

Returns: com.aspose.imaging.Color[] - The scan line pixel color values array.

readArgb32ScanLine(int scanLineIndex)

public int[] readArgb32ScanLine(int scanLineIndex)

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

Parameters:

ParameterTypeDescription
scanLineIndexintZero based index of the scan line.

Returns: int[] - The scan line 32-bit ARGB color values array.

writeScanLine(int scanLineIndex, Color[] pixels)

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

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

Parameters:

ParameterTypeDescription
scanLineIndexintZero based index of the scan line.
pixelsColor[]The pixel colors array to write.

writeArgb32ScanLine(int scanLineIndex, int[] argb32Pixels)

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

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

Parameters:

ParameterTypeDescription
scanLineIndexintZero based index of the scan line.
argb32Pixelsint[]The 32-bit ARGB colors array to write.

loadPartialArgb32Pixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)

public void loadPartialArgb32Pixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)

Loads 32-bit ARGB pixels partially by packs.

Parameters:

ParameterTypeDescription
rectangleRectangleThe desired rectangle.
partialPixelLoaderIPartialArgb32PixelLoaderThe 32-bit ARGB pixel loader.

Example: The following example shows how to load and process pixels of a raster image using your own partial processor. 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(Rectangle desiredRectangle, IPartialPixelLoader pixelLoader)

public void loadPartialPixels(Rectangle desiredRectangle, IPartialPixelLoader pixelLoader)

Loads pixels partially by packs.

Parameters:

ParameterTypeDescription
desiredRectangleRectangleThe desired rectangle.
pixelLoaderIPartialPixelLoaderThe pixel loader.

Example: The following example shows how to load and process pixels of a raster image using your own partial processor. 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(Rectangle rectangle)

public int[] loadArgb32Pixels(Rectangle rectangle)

Loads 32-bit ARGB pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns: int[] - The loaded 32-bit ARGB pixels array.

Example: The following example shows how to load and process pixels of a raster image. 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(Rectangle rectangle)

public long[] loadArgb64Pixels(Rectangle rectangle)

Loads 64-bit ARGB pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns: long[] - The loaded 64-bit ARGB pixels array.

Example: The following example shows how to load and process pixels of a raster image. 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();
}

loadPartialArgb64Pixels(Rectangle rectangle, IPartialArgb64PixelLoader partialPixelLoader)

public final void loadPartialArgb64Pixels(Rectangle rectangle, IPartialArgb64PixelLoader partialPixelLoader)

Loads 64-bit ARGB pixels partially by packs.

Parameters:

ParameterTypeDescription
rectangleRectangleThe desired rectangle.
partialPixelLoaderIPartialArgb64PixelLoaderThe 64-bit ARGB pixel loader.

loadPixels(Rectangle rectangle)

public Color[] loadPixels(Rectangle rectangle)

Loads pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns: com.aspose.imaging.Color[] - The loaded pixels array.

Example: The following example shows how to load and process pixels of a raster image. 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(Rectangle rectangle)

public CmykColor[] loadCmykPixels(Rectangle rectangle)

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

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns: com.aspose.imaging.CmykColor[] - The loaded CMYK pixels array.

loadCmyk32Pixels(Rectangle rectangle)

public int[] loadCmyk32Pixels(Rectangle rectangle)

Loads pixels in CMYK format.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns: int[] - The loaded CMYK pixels presents as 32-bit integer values.

loadRawData(Rectangle rectangle, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)

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

Loads raw image data using the partial processing mechanism.

Parameters:

ParameterTypeDescription
rectangleRectangleThe desired rectangular area of the image to load data from.
rawDataSettingsRawDataSettingsThe raw data settings.
rawDataLoaderIPartialRawDataLoaderThe raw data loader.

Example: The following example shows how to extract pixels from the raw image data using RawDataSettings. 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(Rectangle rectangle, Rectangle dstImageBounds, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)

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

Loads raw data.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load raw data from.
dstImageBoundsRectangleThe destination image bounds.
rawDataSettingsRawDataSettingsThe raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
rawDataLoaderIPartialRawDataLoaderThe raw data loader.

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

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

Saves the raw data.

Parameters:

ParameterTypeDescription
databyte[]The raw data.
dataOffsetintThe starting raw data offset.
rectangleRectangleThe raw data rectangle.
rawDataSettingsRawDataSettingsThe raw data settings the data is in.

saveArgb32Pixels(Rectangle rectangle, int[] pixels)

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

Saves the 32-bit ARGB pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsint[]The 32-bit ARGB pixels array.

Example: The following example fills the central area of a raster image with black pixels using the com. 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(Rectangle rectangle, Color[] pixels)

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

Saves the pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsColor[]The pixels array.

Example: The following example fills the central area of a raster image with black pixels using the com. 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: java.awt.image.BufferedImage - The bitmap

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(Rectangle rectangle, CmykColor[] pixels)

public void saveCmykPixels(Rectangle rectangle, CmykColor[] pixels)

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

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsCmykColor[]The CMYK pixels array.

saveCmyk32Pixels(Rectangle rectangle, int[] pixels)

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

Saves the pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsint[]The CMYK pixels presented as the 32-bit integer values.

Example: The following example fills the central area of a raster image with black pixels using the com. 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(double dpiX, double dpiY)

public void setResolution(double dpiX, double dpiY)

Sets the resolution for this RasterImage.

Parameters:

ParameterTypeDescription
dpiXdoubleThe horizontal resolution, in dots per inch, of the RasterImage.
dpiYdoubleThe vertical resolution, in dots per inch, of the RasterImage.

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(IColorPalette palette, boolean updateColors)

public void setPalette(IColorPalette palette, boolean updateColors)

Sets the image palette.

Parameters:

ParameterTypeDescription
paletteIColorPaletteThe palette to set.
updateColorsbooleanif 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(int newWidth, int newHeight, ImageResizeSettings settings)

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

Resizes the image with extended options.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.
settingsImageResizeSettingsThe resize settings.

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

rotate(float angle, boolean resizeProportionally, Color backgroundColor)

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

Rotate image around the center.

Parameters:

ParameterTypeDescription
anglefloatThe rotate angle in degrees. Positive values will rotate clockwise.
resizeProportionallybooleanif 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.
backgroundColorColorColor of the background.

rotate(float angle)

public void rotate(float angle)

Rotate image around the center.

Parameters:

ParameterTypeDescription
anglefloatThe rotate angle in degrees. Positive values will rotate clockwise.

binarizeFixed(byte threshold)

public void binarizeFixed(byte threshold)

Binarization of an image with predefined threshold

Parameters:

ParameterTypeDescription
thresholdbyteThreshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.

Example: The following example binarizes a raster image with the predefined threshold. 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

Example: The following example binarizes a raster image with Otsu thresholding. 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(double brightnessDifference)

public void binarizeBradley(double brightnessDifference)

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

Parameters:

ParameterTypeDescription
brightnessDifferencedoubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.

binarizeBradley(double brightnessDifference, int windowSize)

public void binarizeBradley(double brightnessDifference, int windowSize)

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

Parameters:

ParameterTypeDescription
brightnessDifferencedoubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
windowSizeintThe size of s x s window of pixels centered around this pixel

Example: The following example binarizes a raster image with Bradley’s adaptive thresholding algorithm with the specified window size. 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();
}

blend(Point origin, RasterImage overlay, Rectangle overlayArea)

public final void blend(Point origin, RasterImage overlay, Rectangle overlayArea)

Blends this image instance with the overlay image.

Parameters:

ParameterTypeDescription
originPointThe background image blending origin.
overlayRasterImageThe overlay image.
overlayAreaRectangleThe overlay area.

blend(Point origin, RasterImage overlay, Rectangle overlayArea, byte overlayAlpha)

public void blend(Point origin, RasterImage overlay, Rectangle overlayArea, byte overlayAlpha)

Blends this image instance with the overlay image.

Parameters:

ParameterTypeDescription
originPointThe background image blending origin.
overlayRasterImageThe overlay image.
overlayAreaRectangleThe overlay area.
overlayAlphabyteThe overlay alpha.

blend(Point origin, RasterImage overlay)

public final void blend(Point origin, RasterImage overlay)

Blends this image instance with the overlay with alpha == 255.

Parameters:

ParameterTypeDescription
originPointThe background image blending origin.
overlayRasterImageThe overlay.

blend(Point origin, RasterImage overlay, byte overlayAlpha)

public final void blend(Point origin, RasterImage overlay, byte overlayAlpha)

Blends this image instance with the overlay.

Parameters:

ParameterTypeDescription
originPointThe background image blending origin.
overlayRasterImageThe overlay.
overlayAlphabyteThe overlay alpha.

grayscale()

public void grayscale()

Transformation of an image to its grayscale representation

Example: The following example transforms a colored raster image to its grayscale representation. 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(int brightness)

public void adjustBrightness(int brightness)

Adjust of a brightness for image.

Parameters:

ParameterTypeDescription
brightnessintBrightness value.

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(float contrast)

public void adjustContrast(float contrast)

Image contrasting

Parameters:

ParameterTypeDescription
contrastfloatContrast value (in range [-100; 100])

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(float gammaRed, float gammaGreen, float gammaBlue)

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

Gamma-correction of an image.

Parameters:

ParameterTypeDescription
gammaRedfloatGamma for red channel coefficient
gammaGreenfloatGamma for green channel coefficient
gammaBluefloatGamma for blue channel coefficient

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(float gamma)

public void adjustGamma(float gamma)

Gamma-correction of an image.

Parameters:

ParameterTypeDescription
gammafloatGamma for red, green and blue channels coefficient

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

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: float - The skew angle, in degrees.

normalizeAngle()

public final void normalizeAngle()

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

normalizeAngle(boolean resizeProportionally, Color backgroundColor)

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 .getSkewAngle and .rotate(float, boolean, Color) methods.

Parameters:

ParameterTypeDescription
resizeProportionallybooleanif 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.
backgroundColorColorColor of the background.

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. 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(Rectangle rectangle, FilterOptionsBase options)

public void filter(Rectangle rectangle, FilterOptionsBase options)

Filters the specified rectangle.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle.
optionsFilterOptionsBaseThe options.

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(Color oldColor, byte oldColorDiff, Color newColor)

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:

ParameterTypeDescription
oldColorColorOld color to be replaced.
oldColorDiffbyteAllowed difference in old color to be able to widen replaced color tone.
newColorColorNew color to replace old color with.

replaceColor(int oldColorArgb, byte oldColorDiff, int newColorArgb)

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:

ParameterTypeDescription
oldColorArgbintOld color ARGB value to be replaced.
oldColorDiffbyteAllowed difference in old color to be able to widen replaced color tone.
newColorArgbintNew color ARGB value to replace old color with.

replaceNonTransparentColors(Color newColor)

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:

ParameterTypeDescription
newColorColorNew color to replace non-transparent colors with.

replaceNonTransparentColors(int newColorArgb)

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:

ParameterTypeDescription
newColorArgbintNew color ARGB value to replace non-transparent colors with.