public final class GifImage extends RasterImage
A gif image.
This example shows how to create a GIF image and save it to a file.
String dir = "c:\\temp\\"; // Create a GIF Frame block of 100x100 px. com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock firstBlock = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); try { // Fill the entire block in red. com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(firstBlock); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed()); gr.fillRectangle(brush, firstBlock.getBounds()); com.aspose.imaging.fileformats.gif.GifImage gifImage = new com.aspose.imaging.fileformats.gif.GifImage(firstBlock); try { gifImage.save(dir + "output.gif"); } finally { gifImage.dispose(); } } finally { firstBlock.dispose(); }
Constructor and Description |
---|
GifImage(GifFrameBlock firstFrame)
Initializes a new instance of the
GifImage class. |
GifImage(GifFrameBlock firstFrame,
IColorPalette globalPalette)
Initializes a new instance of the
GifImage class. |
GifImage(GifFrameBlock firstFrame,
IColorPalette globalPalette,
boolean isPaletteSorted,
byte paletteColorResolution,
byte paletteBackgroundColorIndex,
byte aspectRatio,
boolean hasTrailer)
Initializes a new instance of the
GifImage class. |
Modifier and Type | Method and Description |
---|---|
void |
addBlock(IGifBlock block)
Adds a new GIF block.
|
void |
adjustBrightness(int brightness)
Adjust of a brightness for image.
|
void |
adjustContrast(float contrast)
Image contrasting
|
void |
adjustGamma(float gamma)
Gamma-correction of an image.
|
void |
adjustGamma(float gammaRed,
float gammaGreen,
float gammaBlue)
Gamma-correction of an image.
|
void |
binarizeBradley(double brightnessDifference)
Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding
|
void |
binarizeFixed(byte threshold)
Binarization of an image with predefined threshold
|
void |
binarizeOtsu()
Binarization of an image with Otsu thresholding
|
void |
cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying
DataStreamSupporter.DataStreamContainer . |
void |
clearBlocks()
Clears all the GIF blocks.
|
void |
crop(Rectangle rectangle)
Cropping the image.
|
void |
dither(int ditheringMethod,
int bitsCount,
IColorPalette customPalette)
Performs dithering on the current image.
|
void |
filter(Rectangle rectangle,
FilterOptionsBase options)
Filters the specified rectangle.
|
GifFrameBlock |
getActiveFrame()
Gets or sets the active frame.
|
Color |
getBackgroundColor()
Gets the background color.
|
byte |
getBackgroundColorIndex()
Gets or sets the background color index.
|
int |
getBitsPerPixel()
Gets the bits per pixel count.
|
IGifBlock[] |
getBlocks()
Gets the GIF blocks.
|
long |
getFileFormat()
Gets a value of file format
|
int |
getHeight()
Gets the object height.
|
float |
getImageOpacity()
Gets opacity of this image.
|
byte |
getPaletteColorResolutionBits()
Gets or sets the palette color resolution bits.
|
byte |
getPixelAspectRatio()
Gets the pixel aspect ratio.
|
Color |
getTransparentColor()
Gets active frame transparent color.
|
int |
getWidth()
Gets the object width.
|
XmpPacketWrapper |
getXmpData()
Gets the XMP metadata.
|
void |
grayscale()
Transformation of an image to its grayscale representation
|
boolean |
hasBackgroundColor()
Gets a value indicating whether image has background color.
|
boolean |
hasTrailer()
Gets or sets a value indicating whether GIF has trailer.
|
boolean |
hasTransparentColor()
Gets a value indicating whether active frame has transparent color.
|
void |
insertBlock(int index,
IGifBlock block)
Adds a new GIF block.
|
boolean |
isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
|
boolean |
isPaletteSorted()
Gets or sets a value indicating whether palette is sorted.
|
void |
normalizeAngle(boolean resizeProportionally,
Color backgroundColor)
Normalizes the angle.
|
void |
orderBlocks()
Orders the GIF blocks according to the GIF specification.
|
void |
removeBlock(IGifBlock block)
Removes the GIF block.
|
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.
|
void |
replaceNonTransparentColors(int newColorArgb)
Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.
|
void |
resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Resizes the image with extended options.
|
void |
resize(int newWidth,
int newHeight,
int resizeType)
Resizes the image.
|
void |
resizeProportional(int newWidth,
int newHeight,
int resizeType)
Performs proportional resize on the image.
|
void |
rotate(float angle,
boolean resizeProportionally,
Color backgroundColor)
Rotate image around the center.
|
void |
rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
|
void |
rotateFlipAll(int rotateFlip)
Rotates the flip all frames in the image.
|
void |
setActiveFrame(GifFrameBlock value)
Sets the active frame.
|
void |
setBackgroundColor(Color value)
Sets the background color.
|
void |
setBackgroundColorIndex(byte value)
Sets the background color index.
|
void |
setPaletteColorResolutionBits(byte value)
Sets the palette color resolution bits.
|
void |
setPaletteSorted(boolean value)
Gets or sets a value indicating whether palette is sorted.
|
void |
setPixelAspectRatio(byte value)
Gets or sets the pixel aspect ratio.
|
void |
setTrailer(boolean value)
Gets or sets a value indicating whether GIF has trailer.
|
void |
setTransparentColor(boolean value)
Gets a value indicating whether active frame has transparent color.
|
void |
setXmpData(XmpPacketWrapper value)
Sets the XMP metadata.
|
binarizeBradley, crop, dither, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getHorizontalResolution, getModifyDate, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataFormat, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getUpdateXmpData, getUseRawData, getVerticalResolution, hasAlpha, isRawDataAvailable, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, readArgb32ScanLine, readScanLine, replaceColor, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setHorizontalResolution, setPalette, setPixel, setPremultiplyComponents, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setResolution, setTransparentColor, setUpdateXmpData, setUseRawData, setVerticalResolution, toBitmap, writeArgb32ScanLine, writeScanLine
canLoad, canLoad, canLoad, canLoad, canSave, create, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getOriginalOptions, getPalette, getProportionalHeight, getProportionalWidth, getSize, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalette
getDataStreamContainer, save, save, save, save
close, dispose, getDisposed
public GifImage(GifFrameBlock firstFrame, IColorPalette globalPalette)
Initializes a new instance of the GifImage
class.
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.com.aspose.ms.System.ArgumentNullException
- The frame cannot be null;firstFramecom.aspose.ms.System.ArgumentException
- The first frame already belongs to some other image. Check the Container property.;firstFrameGifImageException
- The palette specified should contain entries count equal to power of 2. Minimal palette size is 2, maximal is 256.This example shows how to create a GIF image with a custom palette and save it to a file.
String dir = "c:\\temp\\"; // Create a GIF Frame block of 100x100 px. com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock firstBlock = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); try { // Fill the entire block in red. com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(firstBlock); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed()); gr.fillRectangle(brush, firstBlock.getBounds()); // Use 4-bit palette to reduce the image size. The quality can get worse. com.aspose.imaging.IColorPalette palette = com.aspose.imaging.ColorPaletteHelper.create4Bit(); com.aspose.imaging.fileformats.gif.GifImage gifImage = new com.aspose.imaging.fileformats.gif.GifImage(firstBlock, palette); try { gifImage.save(dir + "output.gif"); } finally { gifImage.dispose(); } } finally { firstBlock.dispose(); }
public GifImage(GifFrameBlock firstFrame)
Initializes a new instance of the GifImage
class.
firstFrame
- The first frame to initialize gif image with.com.aspose.ms.System.ArgumentNullException
- The frame cannot be null;firstFramecom.aspose.ms.System.ArgumentException
- The first frame already belongs to some other image. Check the Container property.;firstFrameGifImageException
- The palette specified should contain entries count equal to power of 2. Minimal palette size is 2, maximal is 256.The following example shows how to compose an animated GIF image from individual GIF blocks.
String dir = "c:\\temp\\"; // Create a GIF image 100 x 100 px. // The first block is fully black by default. com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock firstBlock = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.fileformats.gif.GifImage gifImage = new com.aspose.imaging.fileformats.gif.GifImage(firstBlock); try { // The first circle is red com.aspose.imaging.brushes.SolidBrush brush1 = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed()); // The second circle is black com.aspose.imaging.brushes.SolidBrush brush2 = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getBlack()); // Gradually increase the angle of the red arc shape. for (int angle = 10; angle <= 360; angle += 10) { com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock block = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(block); gr.fillPie(brush1, block.getBounds(), 0, angle); gifImage.addBlock(block); } // Gradually increase the angle of the black arc and wipe out the red arc. for (int angle = 10; angle <= 360; angle += 10) { com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock block = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(block); gr.fillPie(brush2, block.getBounds(), 0, angle); gr.fillPie(brush1, block.getBounds(), angle, 360 - angle); gifImage.addBlock(block); } gifImage.save(dir + "animated_radar.gif"); } finally { firstBlock.dispose(); gifImage.dispose(); }
public GifImage(GifFrameBlock firstFrame, IColorPalette globalPalette, boolean isPaletteSorted, byte paletteColorResolution, byte paletteBackgroundColorIndex, byte aspectRatio, boolean hasTrailer)
Initializes a new instance of the GifImage
class.
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.com.aspose.ms.System.ArgumentNullException
- The frame cannot be null;firstFramecom.aspose.ms.System.ArgumentException
- The first frame already belongs to some other image. Check the Container property.;firstFrameGifImageException
- The palette specified should contain entries count equal to power of 2. Minimal palette size is 2, maximal is 256.public long getFileFormat()
Gets a value of file format
getFileFormat
in class Image
public XmpPacketWrapper getXmpData()
Gets the XMP metadata.
getXmpData
in class RasterImage
public void setXmpData(XmpPacketWrapper value)
Sets the XMP metadata.
setXmpData
in class RasterImage
value
- The XMP metadata.public boolean hasTrailer()
Gets or sets a value indicating whether GIF has trailer.
true
if GIF has trailer; otherwise, false
.public void setTrailer(boolean value)
Gets or sets a value indicating whether GIF has trailer.
value
- true
if GIF has trailer; otherwise, false
.public boolean isPaletteSorted()
Gets or sets a value indicating whether palette is sorted.
true
if palette is sorted; otherwise, false
.public void setPaletteSorted(boolean value)
Gets or sets a value indicating whether palette is sorted.
value
- true
if palette is sorted; otherwise, false
.public byte getPaletteColorResolutionBits()
Gets or sets the palette color resolution bits.
public void setPaletteColorResolutionBits(byte value)
Sets the palette color resolution bits.
value
- The palette color resolution bits.public int getWidth()
Gets the object width.
getWidth
in interface IObjectWithBounds
getWidth
in class Image
public int getHeight()
Gets the object height.
getHeight
in interface IObjectWithBounds
getHeight
in class Image
public int getBitsPerPixel()
Gets the bits per pixel count.
getBitsPerPixel
in class Image
For GIF this value is calculated from active frame.
public IGifBlock[] getBlocks()
Gets the GIF blocks.
public GifFrameBlock getActiveFrame()
Gets or sets the active frame.
The following example shows how to remove all blocks from a GIF image.
com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock firstBlock = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.fileformats.gif.GifImage gifImage = new com.aspose.imaging.fileformats.gif.GifImage(firstBlock); try { if (gifImage.getActiveFrame() != null) { System.out.println("Active frame size: " + gifImage.getActiveFrame().getSize()); } else { System.out.println("Active frame is not set"); } System.out.println("Clear all the blocks"); gifImage.clearBlocks(); if (gifImage.getActiveFrame() != null) { System.out.println("Active frame size: " + gifImage.getActiveFrame().getSize()); } else { System.out.println("Active frame is not set"); } } finally { firstBlock.dispose(); gifImage.dispose(); } // The output looks like this: // Active frame size: { Width = 100, Height = 100} // Clear all the blocks // Active frame is not set
public void setActiveFrame(GifFrameBlock value)
Sets the active frame.
value
- The active frame.public Color getBackgroundColor()
Gets the background color.
getBackgroundColor
in class Image
public void setBackgroundColor(Color value)
Sets the background color.
setBackgroundColor
in class Image
value
- The background color.public byte getBackgroundColorIndex()
Gets or sets the background color index.
public void setBackgroundColorIndex(byte value)
Sets the background color index.
value
- The background color index.public byte getPixelAspectRatio()
Gets the pixel aspect ratio.
public void setPixelAspectRatio(byte value)
Gets or sets the pixel aspect ratio.
value
- The pixel aspect ratio.public final boolean isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
isCached
in class DataStreamSupporter
true
if object's data is cached; otherwise, false
.public boolean hasTransparentColor()
Gets a value indicating whether active frame has transparent color.
hasTransparentColor
in class RasterImage
public void setTransparentColor(boolean value)
Gets a value indicating whether active frame has transparent color.
setTransparentColor
in class RasterImage
public Color getTransparentColor()
Gets active frame transparent color.
getTransparentColor
in class RasterImage
public boolean hasBackgroundColor()
Gets a value indicating whether image has background color.
hasBackgroundColor
in class Image
public float getImageOpacity()
Gets opacity of this image. 0 = fully transparent, 1 = fully opaque.
getImageOpacity
in class RasterImage
public void dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)
Performs dithering on the current image.
dither
in class RasterImage
ditheringMethod
- The dithering method.bitsCount
- The final bits count for dithering.customPalette
- The custom palette for dithering.The following example loads a GIF 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.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) 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. gifImage.dither(com.aspose.imaging.DitheringMethod.ThresholdDithering, 4, null); gifImage.save(dir + "sample.ThresholdDithering4.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) 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. gifImage.dither(com.aspose.imaging.DitheringMethod.FloydSteinbergDithering, 1, null); gifImage.save(dir + "sample.FloydSteinbergDithering1.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public final void cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer
.
cacheData
in class DataStreamSupporter
public void rotateFlipAll(int rotateFlip)
Rotates the flip all frames in the image.
rotateFlip
- The rotate flip type to perform.public void orderBlocks()
Orders the GIF blocks according to the GIF specification. Some GifGraphicsControlBlock
may be removed for proper GIF layout.
public void clearBlocks()
Clears all the GIF blocks.
The following example shows how to remove all blocks from a GIF image.
com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock firstBlock = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.fileformats.gif.GifImage gifImage = new com.aspose.imaging.fileformats.gif.GifImage(firstBlock); try { if (gifImage.getActiveFrame() != null) { System.out.println("Active frame size: " + gifImage.getActiveFrame().getSize()); } else { System.out.println("Active frame is not set"); } System.out.println("Clear all the blocks"); gifImage.clearBlocks(); if (gifImage.getActiveFrame() != null) { System.out.println("Active frame size: " + gifImage.getActiveFrame().getSize()); } else { System.out.println("Active frame is not set"); } } finally { firstBlock.dispose(); gifImage.dispose(); } // The output looks like this: // Active frame size: { Width = 100, Height = 100} // Clear all the blocks // Active frame is not set
public void insertBlock(int index, IGifBlock block)
Adds a new GIF block.
index
- The zero-based element, at which block will be inserted.block
- The GIF block to add.public void addBlock(IGifBlock block)
Adds a new GIF block.
block
- The GIF block to add.The following example shows how to compose an animated GIF image from individual GIF blocks.
String dir = "c:\\temp\\"; // Create a GIF image 100 x 100 px. // The first block is fully black by default. com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock firstBlock = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.fileformats.gif.GifImage gifImage = new com.aspose.imaging.fileformats.gif.GifImage(firstBlock); try { // The first circle is red com.aspose.imaging.brushes.SolidBrush brush1 = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed()); // The second circle is black com.aspose.imaging.brushes.SolidBrush brush2 = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getBlack()); // Gradually increase the angle of the red arc shape. for (int angle = 10; angle <= 360; angle += 10) { com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock block = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(block); gr.fillPie(brush1, block.getBounds(), 0, angle); gifImage.addBlock(block); } // Gradually increase the angle of the black arc and wipe out the red arc. for (int angle = 10; angle <= 360; angle += 10) { com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock block = new com.aspose.imaging.fileformats.gif.blocks.GifFrameBlock(100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(block); gr.fillPie(brush2, block.getBounds(), 0, angle); gr.fillPie(brush1, block.getBounds(), angle, 360 - angle); gifImage.addBlock(block); } gifImage.save(dir + "animated_radar.gif"); } finally { firstBlock.dispose(); gifImage.dispose(); }
public void removeBlock(IGifBlock block)
Removes the GIF block.
block
- The block to remove.
Note: do not forget to Dispose the block if you will not add it to some other GifImage.
public void rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
rotateFlip
in class Image
rotateFlipType
- The rotate flip type.This example loads a GIF image, rotates it by 90 degrees clockwise and optionally flips the image horizontally and(or) vertically.
// The helper class used in the main example below. class Utils { // The helper method to get a string representation of the file format. public String getRotateFlipTypeString(int rotateFlipType) { if (rotateFlipType == com.aspose.imaging.RotateFlipType.RotateNoneFlipNone) { return "RotateNoneFlipNone"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate90FlipNone) { return "Rotate90FlipNone"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate180FlipNone) { return "Rotate180FlipNone"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate270FlipNone) { return "Rotate270FlipNone"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.RotateNoneFlipX) { return "RotateNoneFlipX"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate90FlipX) { return "Rotate90FlipX"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate180FlipX) { return "Rotate180FlipX"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate270FlipX) { return "Rotate270FlipX"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.RotateNoneFlipY) { return "RotateNoneFlipY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate90FlipY) { return "Rotate90FlipY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate180FlipY) { return "Rotate180FlipY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate270FlipY) { return "Rotate270FlipY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.RotateNoneFlipXY) { return "RotateNoneFlipXY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate90FlipXY) { return "Rotate90FlipXY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate180FlipXY) { return "Rotate180FlipXY"; } else if (rotateFlipType == com.aspose.imaging.RotateFlipType.Rotate270FlipXY) { return "Rotate270FlipXY"; } else { return "UNDEFINED"; } } } // Here is the main example Utils utils = new Utils(); String dir = "c:\\temp\\"; int[] rotateFlipTypes = new int[] { com.aspose.imaging.RotateFlipType.Rotate90FlipNone, com.aspose.imaging.RotateFlipType.Rotate90FlipX, com.aspose.imaging.RotateFlipType.Rotate90FlipXY, com.aspose.imaging.RotateFlipType.Rotate90FlipY, }; for (int rotateFlipType : rotateFlipTypes) { // Rotate, flip and save to the output file. com.aspose.imaging.fileformats.gif.GifImage image = (com.aspose.imaging.fileformats.gif.GifImage) com.aspose.imaging.Image.load(dir + "sample.gif"); try { image.rotateFlip(rotateFlipType); image.save(dir + "sample." + utils.getRotateFlipTypeString(rotateFlipType) + ".png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } }
public void rotate(float angle, boolean resizeProportionally, Color backgroundColor)
Rotate image around the center.
rotate
in class RasterImage
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.public void normalizeAngle(boolean resizeProportionally, Color backgroundColor)
Normalizes the angle.
This method is applicable to scanned text documents to get rid of the skewed scan.
This method uses RasterImage.getSkewAngle()
and RasterImage.rotate(float,boolean,Color)
methods.
normalizeAngle
in class RasterImage
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.public void resize(int newWidth, int newHeight, int resizeType)
Resizes the image.
resize
in class RasterImage
newWidth
- The new width.newHeight
- The new height.resizeType
- The resize type.This example loads a GIF image and resizes it using various resizing methods.
String dir = "c:\\temp\\"; com.aspose.imaging.fileformats.gif.GifImage image = (com.aspose.imaging.fileformats.gif.GifImage) com.aspose.imaging.Image.load(dir + "sample.gif"); try { // Scale up by 2 times using Nearest Neighbour resampling. image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); image.save(dir + "upsample.nearestneighbour.gif"); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.gif.GifImage) com.aspose.imaging.Image.load(dir + "sample.gif"); try { // Scale down by 2 times using Nearest Neighbour resampling. image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); image.save(dir + "downsample.nearestneighbour.gif"); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.gif.GifImage) com.aspose.imaging.Image.load(dir + "sample.gif"); try { // Scale up by 2 times using Bilinear resampling. image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample); image.save(dir + "upsample.bilinear.gif"); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.gif.GifImage) com.aspose.imaging.Image.load(dir + "sample.gif"); try { // Scale down by 2 times using Bilinear resampling. image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample); image.save(dir + "downsample.bilinear.gif"); } finally { image.dispose(); }
public void resize(int newWidth, int newHeight, ImageResizeSettings settings)
Resizes the image with extended options.
resize
in class RasterImage
newWidth
- The new width.newHeight
- The new height.settings
- The resize settings.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.This example loads a GIF 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.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Scale down by 2 times using adaptive resampling. gifImage.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings); // Save to PNG gifImage.save(dir + "downsample.adaptive.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
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.
newWidth
- The new width.newHeight
- The new height.resizeType
- The resize type.public void crop(Rectangle rectangle)
Cropping the image.
crop
in class RasterImage
rectangle
- The rectangle.The following example crops a GIF image. The cropping area is be specified via Aspose.Imaging.Rectangle.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Crop the image. The cropping area is the rectangular central area of the image. com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle( gifImage.getWidth() / 4, gifImage.getHeight() / 4, gifImage.getWidth() / 2, gifImage.getHeight() / 2); gifImage.crop(area); // Save the cropped image to PNG gifImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void grayscale()
Transformation of an image to its grayscale representation
grayscale
in class RasterImage
The following example transforms a colored GIF 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.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; gifImage.grayscale(); gifImage.save(dir + "sample.Grayscale.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void binarizeFixed(byte threshold)
Binarization of an image with predefined threshold
binarizeFixed
in class RasterImage
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.The following example binarizes a GIF 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.gif"); try { com.aspose.imaging.fileformats.gif.GifImage djvuImage = (com.aspose.imaging.fileformats.gif.GifImage) 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. djvuImage.binarizeFixed((byte) 127); djvuImage.save(dir + "sample.BinarizeFixed.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void binarizeOtsu()
Binarization of an image with Otsu thresholding
binarizeOtsu
in class RasterImage
The following example binarizes a GIF 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.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Binarize the image with Otsu thresholding. gifImage.binarizeOtsu(); gifImage.save(dir + "sample.BinarizeOtsu.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void binarizeBradley(double brightnessDifference)
Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding
binarizeBradley
in class RasterImage
brightnessDifference
- The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.public void adjustBrightness(int brightness)
Adjust of a brightness for image.
adjustBrightness
in class RasterImage
brightness
- Brightness value.The following example performs brightness correction of a GIF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Set the brightness value. The accepted values of brightness are in the range [-255, 255]. gifImage.adjustBrightness(50); gifImage.save(dir + "sample.AdjustBrightness.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void adjustContrast(float contrast)
Image contrasting
adjustContrast
in class RasterImage
contrast
- Contrast value (in range [-100; 100])The following example performs contrast correction of a GIF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Set the contrast value. The accepted values of contrast are in the range [-100f, 100f]. gifImage.adjustContrast(50f); gifImage.save(dir + "sample.AdjustContrast.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)
Gamma-correction of an image.
adjustGamma
in class RasterImage
gammaRed
- Gamma for red channel coefficientgammaGreen
- Gamma for green channel coefficientgammaBlue
- Gamma for blue channel coefficientThe following example performs gamma-correction of a GIF image applying different coefficients for color components.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Set individual gamma coefficients for red, green and blue channels. gifImage.adjustGamma(1.5f, 2.5f, 3.5f); gifImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void adjustGamma(float gamma)
Gamma-correction of an image.
adjustGamma
in class RasterImage
gamma
- Gamma for red, green and blue channels coefficientThe following example performs gamma-correction of a GIF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Set gamma coefficient for red, green and blue channels. gifImage.adjustGamma(2.5f); gifImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void filter(Rectangle rectangle, FilterOptionsBase options)
Filters the specified rectangle.
filter
in class RasterImage
rectangle
- The rectangle.options
- The options.The following example applies various types of filters to a GIF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Apply a median filter with a rectangle size of 5 to the entire image. gifImage.filter(gifImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(5)); gifImage.save(dir + "sample.MedianFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Apply a bilateral smoothing filter with a kernel size of 5 to the entire image. gifImage.filter(gifImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(5)); gifImage.save(dir + "sample.BilateralSmoothingFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image. gifImage.filter(gifImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions(5, 4.0)); gifImage.save(dir + "sample.GaussianBlurFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image. gifImage.filter(gifImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussWienerFilterOptions(5, 4.0)); gifImage.save(dir + "sample.GaussWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) 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. gifImage.filter(gifImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MotionWienerFilterOptions(10, 1.0, 90.0)); gifImage.save(dir + "sample.MotionWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { com.aspose.imaging.fileformats.gif.GifImage gifImage = (com.aspose.imaging.fileformats.gif.GifImage) image; // Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image. gifImage.filter(gifImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions(5, 4.0)); gifImage.save(dir + "sample.SharpenFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
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.
replaceColor
in class RasterImage
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.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.
replaceNonTransparentColors
in class RasterImage
newColorArgb
- New color ARGB value to replace non transparent colors with.Copyright (c) 2008-2019 Aspose Pty Ltd. All Rights Reserved.