public abstract class RasterCachedImage extends RasterImage
Represents a raster image supporting raster graphics operations. This image caches pixel data when required.
The following example transforms a colored raster cached 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) image; rasterImage.grayscale(); rasterImage.save(dir + "sample.Grayscale.png"); } finally { image.dispose(); }
Modifier and Type | Method and Description |
---|---|
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 |
binarizeBradley(double brightnessDifference,
int windowSize)
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 |
crop(Rectangle rectangle)
Cropping the image.
|
void |
dither(int ditheringMethod,
int bitsCount,
IColorPalette customPalette)
Performs dithering on the current image.
|
void |
grayscale()
Transformation of an image to its grayscale representation
|
boolean |
isCached()
Gets a value indicating whether image data is cached currently.
|
void |
resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Resizes the image.
|
void |
resize(int newWidth,
int newHeight,
int resizeType)
Resizes 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.
|
crop, dither, filter, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getHorizontalResolution, getImageOpacity, getModifyDate, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataFormat, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, getVerticalResolution, getXmpData, hasAlpha, hasTransparentColor, isRawDataAvailable, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, normalizeAngle, readArgb32ScanLine, readScanLine, replaceColor, replaceColor, replaceNonTransparentColors, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setHorizontalResolution, setPalette, setPixel, setPremultiplyComponents, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setResolution, setTransparentColor, setTransparentColor, setUpdateXmpData, setUseRawData, setVerticalResolution, setXmpData, toBitmap, writeArgb32ScanLine, writeScanLine
canLoad, canLoad, canLoad, canLoad, canSave, create, getBackgroundColor, getBitsPerPixel, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getHeight, getInterruptMonitor, getOriginalOptions, getPalette, getProgressEventHandler, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSize, getWidth, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalette
getDataStreamContainer, save, save, save, save
close, dispose, getDisposed
public boolean isCached()
Gets a value indicating whether image data is cached currently.
isCached
in class DataStreamSupporter
true
if image data is cached; otherwise, false
.public void cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer
.
cacheData
in class DataStreamSupporter
The following example shows how raster image caching affects performance. In general case, reading cached data is performed faster than reading non-cached data.
String dir = "c:\\temp\\"; // Load an image from a PNG file. com.aspose.imaging.RasterCachedImage image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { // Cache all pixel data so that no additional data loading will be performed from the underlying data stream image.cacheData(); long startTime = System.currentTimeMillis(); // Reading all pixels is pretty fast. for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int color = image.getArgb32Pixel(x, y); } } long stopTime = System.currentTimeMillis(); long elapsedMilliseconds = stopTime - startTime; System.out.println("Reading all cached pixels took " + elapsedMilliseconds + " ms."); } finally { image.dispose(); } // Load an image from a PNG file image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { long startTime = System.currentTimeMillis(); // Reading all pixels is not as fast as when caching for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int color = image.getArgb32Pixel(x, y); } } long stopTime = System.currentTimeMillis(); long elapsedMilliseconds = stopTime - startTime; System.out.println("Reading all pixels without preliminary caching took " + elapsedMilliseconds + " ms."); } finally { image.dispose(); } // The output may look like this: //Reading all cached pixels took 2923 ms. // java.lang.OutOfMemoryError //at com.aspose.imaging.internal.G.be.b(Unknown Source) //at com.aspose.imaging.internal.G.be.a(Unknown Source) //at com.aspose.imaging.internal.G.be.a(Unknown Source) //at com.aspose.imaging.internal.G.be.a(Unknown Source) //at com.aspose.imaging.internal.G.aB.a(Unknown Source) //at com.aspose.imaging.RasterImage.a(Unknown Source) //at com.aspose.imaging.RasterImage.getArgb32Pixel(Unknown Source) //at com.aspose.examples.ExamplesTest.Test(ExamplesTest.java:54)
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 raster cached image and resizes it using various resizing methods.
String dir = "c:\\temp\\"; com.aspose.imaging.RasterCachedImage image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { // Scale up by 2 times using Nearest Neighbour resampling. image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); // Save to PNG with default options. image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { // Scale down by 2 times using Nearest Neighbour resampling. image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); // Save to PNG with default options. image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { // Scale up by 2 times using Bilinear resampling. image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample); // Save to PNG with default options. image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { // Scale down by 2 times using Bilinear resampling. image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample); // Save to PNG with default options. image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void resize(int newWidth, int newHeight, ImageResizeSettings settings)
Resizes the image.
resize
in class RasterImage
newWidth
- The new width.newHeight
- The new height.settings
- The resize settings.This example loads a raster cached 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.RasterCachedImage image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.png"); try { // Scale down by 2 times using adaptive resampling. image.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings); image.save(dir + "downsample.adaptive.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
rotateFlip
in class Image
rotateFlipType
- The rotate flip type.RotateFlipType
This example loads a raster cached image, rotates it by 90 degrees clockwise and optionally flips the image horizontally and(or) vertically.
String dir = "c:\\temp\\"; // This is a helper class. class LocalHelper { // Gets a string representation of the rotate flip type. public String rotateFlipTypeToString(int rotateFilpType) { switch (rotateFilpType) { case com.aspose.imaging.RotateFlipType.RotateNoneFlipNone: return "RotateNoneFlipNone"; case com.aspose.imaging.RotateFlipType.Rotate90FlipNone: return "Rotate90FlipNone"; case com.aspose.imaging.RotateFlipType.Rotate180FlipNone: return "Rotate180FlipNone"; case com.aspose.imaging.RotateFlipType.Rotate270FlipNone: return "Rotate270FlipNone"; case com.aspose.imaging.RotateFlipType.RotateNoneFlipX: return "RotateNoneFlipX"; case com.aspose.imaging.RotateFlipType.Rotate90FlipX: return "Rotate90FlipX"; case com.aspose.imaging.RotateFlipType.Rotate180FlipX: return "Rotate180FlipX"; case com.aspose.imaging.RotateFlipType.Rotate270FlipX: return "Rotate270FlipX"; case com.aspose.imaging.RotateFlipType.RotateNoneFlipY: return "RotateNoneFlipY"; case com.aspose.imaging.RotateFlipType.Rotate90FlipY: return "Rotate90FlipY"; case com.aspose.imaging.RotateFlipType.Rotate180FlipY: return "Rotate180FlipY"; case com.aspose.imaging.RotateFlipType.Rotate270FlipY: return "Rotate270FlipY"; case com.aspose.imaging.RotateFlipType.RotateNoneFlipXY: return "RotateNoneFlipXY"; case com.aspose.imaging.RotateFlipType.Rotate90FlipXY: return "Rotate90FlipXY"; case com.aspose.imaging.RotateFlipType.Rotate180FlipXY: return "Rotate180FlipXY"; case com.aspose.imaging.RotateFlipType.Rotate270FlipXY: return "Rotate270FlipXY"; default: throw new java.lang.IllegalArgumentException("rotateFlipType"); } } } // Here is the main example int[] rotateFlipTypes = new int[] { com.aspose.imaging.RotateFlipType.Rotate90FlipNone, com.aspose.imaging.RotateFlipType.Rotate90FlipX, com.aspose.imaging.RotateFlipType.Rotate90FlipXY, com.aspose.imaging.RotateFlipType.Rotate90FlipY, }; LocalHelper localHelper = new LocalHelper(); for (int rotateFlipType : rotateFlipTypes) { // Rotate, flip and save to the output file. com.aspose.imaging.RasterCachedImage image = (com.aspose.imaging.RasterCachedImage) com.aspose.imaging.Image.load(dir + "sample.bmp"); try { image.rotateFlip(rotateFlipType); image.save(dir + "sample." + localHelper.rotateFlipTypeToString(rotateFlipType) + ".bmp"); } 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 crop(Rectangle rectangle)
Cropping the image.
crop
in class RasterImage
rectangle
- The rectangle.The following example crops a raster cached image. The cropping area is be specified via com.aspose.imaging.Rectangle.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png"); try { com.aspose.imaging.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) image; // Crop the image. The cropping area is the rectangular central area of the image. int width = rasterImage.getWidth(); int height = rasterImage.getHeight(); com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle(width / 4, height / 4, width / 2, height / 2); rasterImage.crop(area); // Save the cropped image to PNG rasterImage.save(dir + "sample.Crop.png"); } finally { image.dispose(); }
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.public void grayscale()
Transformation of an image to its grayscale representation
grayscale
in class RasterImage
The following example transforms a colored raster cached 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) image; rasterImage.grayscale(); rasterImage.save(dir + "sample.Grayscale.png"); } 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 raster cached 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) 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(); }
public void binarizeOtsu()
Binarization of an image with Otsu thresholding
binarizeOtsu
in class RasterImage
The following example binarizes a raster cached 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) image; // Binarize the image with Otsu thresholding. rasterImage.binarizeOtsu(); rasterImage.save(dir + "sample.BinarizeOtsu.png"); } finally { image.dispose(); }
public void binarizeBradley(double brightnessDifference, int windowSize)
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.windowSize
- The size of s x s window of pixels centered around this pixelThe following example binarizes a raster cached 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) 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(); }
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.The following example binarizes a raster cached image with Bradley's adaptive thresholding algorithm. 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) image; // Binarize the image with a brightness difference of 5. // The brightness is a difference between a pixel and the average of an s x s window of pixels centered around this pixel. // The size of window will be calibrated automatically. rasterImage.binarizeBradley(5); rasterImage.save(dir + "sample.BinarizeBradley5.png"); } finally { image.dispose(); }
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 raster cached image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png"); try { com.aspose.imaging.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) 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(); }
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 raster cached image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png"); try { com.aspose.imaging.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) 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(); }
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 raster cached 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.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) 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(); }
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 raster cached image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png"); try { com.aspose.imaging.RasterCachedImage rasterImage = (com.aspose.imaging.RasterCachedImage) image; // Set gamma coefficient for red, green and blue channels. rasterImage.adjustGamma(2.5f); rasterImage.save(dir + "sample.AdjustGamma.png"); } finally { image.dispose(); }