Packages

 

com.aspose.imaging.fileformats.gif

Class GifImage

    • Constructor Detail

      • GifImage

        public GifImage(GifFrameBlock firstFrame,
                        IColorPalette globalPalette)

        Initializes a new instance of the GifImage class.

        Parameters:
        firstFrame - The first frame to initialize gif image with.
        globalPalette - The global palette to use. Note if both firstFrame and globalPalette are null then default global palette is used.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The frame cannot be null;firstFrame
        com.aspose.ms.System.ArgumentException - The first frame already belongs to some other image. Check the Container property.;firstFrame
        GifImageException - The palette specified should contain entries count equal to power of 2. Minimal palette size is 2, maximal is 256.
      • GifImage

        public GifImage(GifFrameBlock firstFrame)

        Initializes a new instance of the GifImage class.

        Parameters:
        firstFrame - The first frame to initialize gif image with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The frame cannot be null;firstFrame
        com.aspose.ms.System.ArgumentException - The first frame already belongs to some other image. Check the Container property.;firstFrame
        GifImageException - The palette specified should contain entries count equal to power of 2. Minimal palette size is 2, maximal is 256.
      • GifImage

        public GifImage(GifFrameBlock firstFrame,
                        IColorPalette globalPalette,
                        boolean isPaletteSorted,
                        byte paletteColorResolution,
                        byte paletteBackgroundColorIndex,
                        byte aspectRatio,
                        boolean hasTrailer)

        Initializes a new instance of the GifImage class.

        Parameters:
        firstFrame - The first frame to initialize gif image with.
        globalPalette - The global palette to use. Note if both firstFrame and globalPalette are null then default global palette is used.
        isPaletteSorted - if set to true the palette is sorted. Note the parameter is used when globalPalette is not null.
        paletteColorResolution - The palette color resolution. Note the parameter is used when globalPalette is not null.
        paletteBackgroundColorIndex - The palette background color index.
        aspectRatio - The aspect ratio.
        hasTrailer - if set to true the gif image has trailer otherwise no trailer written at the end of the stream.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The frame cannot be null;firstFrame
        com.aspose.ms.System.ArgumentException - The first frame already belongs to some other image. Check the Container property.;firstFrame
        GifImageException - The palette specified should contain entries count equal to power of 2. Minimal palette size is 2, maximal is 256.
    • Method Detail

      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
      • hasTrailer

        public boolean hasTrailer()

        Gets or sets a value indicating whether GIF has trailer.

        Returns:
        true if GIF has trailer; otherwise, false.
      • setTrailer

        public void setTrailer(boolean value)

        Gets or sets a value indicating whether GIF has trailer.

        Parameters:
        value - true if GIF has trailer; otherwise, false.
      • isPaletteSorted

        public boolean isPaletteSorted()

        Gets or sets a value indicating whether palette is sorted.

        Returns:
        true if palette is sorted; otherwise, false.
      • setPaletteSorted

        public void setPaletteSorted(boolean value)

        Gets or sets a value indicating whether palette is sorted.

        Parameters:
        value - true if palette is sorted; otherwise, false.
      • getPaletteColorResolutionBits

        public byte getPaletteColorResolutionBits()

        Gets or sets the palette color resolution bits.

        Returns:
        The palette color resolution bits.
      • setPaletteColorResolutionBits

        public void setPaletteColorResolutionBits(byte value)

        Sets the palette color resolution bits.

        Parameters:
        value - The palette color resolution bits.
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the bits per pixel count.

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

        For GIF this value is calculated from active frame.

      • getBlocks

        public IGifBlock[] getBlocks()

        Gets the GIF blocks.

      • getActiveFrame

        public GifFrameBlock getActiveFrame()

        Gets or sets the active frame.

        Returns:
        The active frame.
      • setActiveFrame

        public void setActiveFrame(GifFrameBlock value)

        Sets the active frame.

        Parameters:
        value - The active frame.
      • getBackgroundColor

        public Color getBackgroundColor()

        Gets the background color.

        Overrides:
        getBackgroundColor in class Image
        Returns:
        The background color.
      • setBackgroundColor

        public void setBackgroundColor(Color value)

        Sets the background color.

        Overrides:
        setBackgroundColor in class Image
        Parameters:
        value - The background color.
      • getBackgroundColorIndex

        public byte getBackgroundColorIndex()

        Gets or sets the background color index.

        Returns:
        The background color index.
      • setBackgroundColorIndex

        public void setBackgroundColorIndex(byte value)

        Sets the background color index.

        Parameters:
        value - The background color index.
      • getPixelAspectRatio

        public byte getPixelAspectRatio()

        Gets the pixel aspect ratio.

        Returns:
        The pixel aspect ratio.
      • setPixelAspectRatio

        public void setPixelAspectRatio(byte value)

        Gets or sets the pixel aspect ratio.

        Parameters:
        value - The pixel aspect ratio.
      • isCached

        public final boolean isCached()

        Gets a value indicating whether object's data is cached currently and no data reading is required.

        Specified by:
        isCached in class DataStreamSupporter
        Returns:
        true if object's data is cached; otherwise, false.
      • hasTransparentColor

        public boolean hasTransparentColor()

        Gets a value indicating whether active frame has transparent color.

        Overrides:
        hasTransparentColor in class RasterImage
      • setTransparentColor

        public void setTransparentColor(boolean value)

        Gets a value indicating whether active frame has transparent color.

        Overrides:
        setTransparentColor in class RasterImage
      • hasBackgroundColor

        public boolean hasBackgroundColor()

        Gets a value indicating whether image has background color.

        Overrides:
        hasBackgroundColor in class Image
      • getImageOpacity

        public float getImageOpacity()

        Gets opacity of this image. 0 = fully transparent, 1 = fully opaque.

        Overrides:
        getImageOpacity in class RasterImage
        Returns:
        The opacity value between 0.0 (fully transparent) and 1.0 (fully opaque).
      • dither

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

        Performs dithering on the current image.

        Specified by:
        dither in class RasterImage
        Parameters:
        ditheringMethod - The dithering method.
        bitsCount - The final bits count for dithering.
        customPalette - The custom palette for dithering.
      • cacheData

        public final void cacheData()

        Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer.

        Specified by:
        cacheData in class DataStreamSupporter
      • rotateFlipAll

        public void rotateFlipAll(int rotateFlip)

        Rotates the flip all frames in the image.

        Parameters:
        rotateFlip - The rotate flip type to perform.
      • orderBlocks

        public void orderBlocks()

        Orders the GIF blocks according to the GIF specification. Some GifGraphicsControlBlock may be removed for proper GIF layout.

      • clearBlocks

        public void clearBlocks()

        Clears all the GIF blocks.

      • insertBlock

        public void insertBlock(int index,
                                IGifBlock block)

        Adds a new GIF block.

        Parameters:
        index - The zero-based element, at which block will be inserted.
        block - The GIF block to add.
      • addBlock

        public void addBlock(IGifBlock block)

        Adds a new GIF block.

        Parameters:
        block - The GIF block to add.
      • removeBlock

        public void removeBlock(IGifBlock block)

        Removes the GIF block.

        Parameters:
        block - The block to remove.

        Note: do not forget to Dispose the block if you will not add it to some other GifImage.

      • rotateFlip

        public void rotateFlip(int rotateFlipType)

        Rotates, flips, or rotates and flips the image.

        Specified by:
        rotateFlip in class Image
        Parameters:
        rotateFlipType - The rotate flip type.
      • rotate

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

        Rotate image around the center.

        Overrides:
        rotate in class RasterImage
        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.
      • resize

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

        Resizes the image.

        Overrides:
        resize in class RasterImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
      • resize

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

        Resizes the image with extended options.

        Overrides:
        resize in class RasterImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        settings - The resize settings.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - newWidth;The new width should be positive number and at least 1. or newHeight;The new height should be positive number and at least 1.
      • resizeProportional

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

        Performs proportional resize on the image. The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.

        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
      • crop

        public void crop(Rectangle rectangle)

        Cropping the image.

        Overrides:
        crop in class RasterImage
        Parameters:
        rectangle - The rectangle.
      • grayscale

        public void grayscale()

        Transformation of an image to its grayscale representation

        Overrides:
        grayscale in class RasterImage
      • binarizeFixed

        public void binarizeFixed(byte threshold)

        Binarization of an image with predefined threshold

        Overrides:
        binarizeFixed in class RasterImage
        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.
      • binarizeOtsu

        public void binarizeOtsu()

        Binarization of an image with Otsu thresholding

        Overrides:
        binarizeOtsu in class RasterImage
      • binarizeBradley

        public void binarizeBradley(double brightnessDifference)

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

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

        public void adjustBrightness(int brightness)

        Adjust of a brightness for image.

        Overrides:
        adjustBrightness in class RasterImage
        Parameters:
        brightness - Brightness value.
      • adjustContrast

        public void adjustContrast(float contrast)

        Image contrasting

        Overrides:
        adjustContrast in class RasterImage
        Parameters:
        contrast - Contrast value (in range [-100; 100])
      • adjustGamma

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

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterImage
        Parameters:
        gammaRed - Gamma for red channel coefficient
        gammaGreen - Gamma for green channel coefficient
        gammaBlue - Gamma for blue channel coefficient
      • adjustGamma

        public void adjustGamma(float gamma)

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterImage
        Parameters:
        gamma - Gamma for red, green and blue channels coefficient
      • filter

        public void filter(Rectangle rectangle,
                           FilterOptionsBase options)

        Filters the specified rectangle.

        Overrides:
        filter in class RasterImage
        Parameters:
        rectangle - The rectangle.
        options - The options.
      • 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.

        Overrides:
        replaceColor in class RasterImage
        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(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.

        Overrides:
        replaceNonTransparentColors in class RasterImage
        Parameters:
        newColorArgb - New color ARGB value to replace non transparent colors with.