public final class TiffImage extends RasterImage
The tiff image.
Constructor and Description |
---|
TiffImage(TiffFrame frame)
Initializes a new instance of the
TiffImage class. |
TiffImage(TiffFrame[] frames)
Initializes a new instance of the
TiffImage class. |
Modifier and Type | Method and Description |
---|---|
void |
add(TiffImage image)
Adds the specified image's frames to current frame.
|
void |
addFrame(TiffFrame frame)
Adds the frame to image
|
void |
addFrames(TiffFrame[] frames)
Adds the frames array to image
|
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 |
alignResolutions()
Helper method to make horizontal and vertical resolutions equal.
|
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(int leftShift,
int rightShift,
int topShift,
int bottomShift)
Crop image with shifts.
|
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.
|
TiffFrame |
getActiveFrame()
Gets or sets the active frame.
|
Color |
getBackgroundColor()
Gets or sets a value for the background color.
|
int |
getBitsPerPixel()
Gets the image bits per pixel value of current frame.
|
int |
getByteOrder()
Gets or sets a value indicating the tiff byte order.
|
ExifData |
getExifData()
Gets or sets EXIF data for the active frame.
|
long |
getFileFormat()
Gets a value of file format
|
TiffFrame[] |
getFrames()
Gets Frames array of the image.
|
int |
getHeight()
Gets the image height.
|
double |
getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this
Image . |
float |
getImageOpacity()
Gets opacity of this image (active frame).
|
boolean |
getPremultiplyComponents()
Gets or sets a value indicating whether components must be premultiplied.
|
double |
getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this
Image . |
int |
getWidth()
Gets the image width.
|
XmpPacketWrapper |
getXmpData()
Gets or sets XMP data from frame.
|
void |
grayscale()
Transformation of an image to its grayscale representation
|
boolean |
hasAlpha()
Gets a value indicating whether this instance has alpha.
|
boolean |
hasTransparentColor()
Gets a value indicating whether image has transparent color.
|
void |
insertFrame(int index,
TiffFrame frameToInsert)
The insert frame.
|
boolean |
isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
|
void |
normalizeAngle(boolean resizeProportionally,
Color backgroundColor)
Normalizes the angle.
|
TiffFrame |
removeFrame(int index)
Removes the frame by its index.
|
void |
removeFrame(TiffFrame frame)
Removes the specified frame.
|
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.
|
TiffFrame |
replaceFrame(int index,
TiffFrame frameToReplace)
Replaces the frame at the specified position.
|
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.
|
void |
resize(int newWidth,
int newHeight,
int resizeType)
Resizes the image.
|
void |
resizeHeightProportionally(int newHeight,
int resizeType)
Resizes the height proportionally.
|
void |
resizeProportional(int newWidth,
int newHeight,
int resizeType)
Performs proportional resize on the image.
|
void |
resizeWidthProportionally(int newWidth,
int resizeType)
Resizes the width proportionally.
|
void |
rotate(float angle,
boolean resizeProportionally,
Color backgroundColor)
Rotate image around the center.
|
void |
rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the Active frame only.
|
void |
rotateFlipAll(int rotateFlip)
Rotates the flip all frames in image.
|
void |
setActiveFrame(TiffFrame value)
Gets or sets the active frame.
|
void |
setBackgroundColor(Color value)
Gets or sets a value for the background color.
|
void |
setByteOrder(int value)
Gets or sets a value indicating the tiff byte order.
|
void |
setExifData(ExifData value)
Gets or sets EXIF data for the active frame.
|
void |
setHorizontalResolution(double value)
Gets the horizontal resolution, in pixels per inch, of this
Image . |
void |
setPremultiplyComponents(boolean value)
Gets or sets a value indicating whether components must be premultiplied.
|
void |
setResolution(double dpiX,
double dpiY)
Sets the resolution for this
RasterImage . |
void |
setTransparentColor(boolean value)
Gets a value indicating whether image has transparent color.
|
void |
setVerticalResolution(double value)
Gets the vertical resolution, in pixels per inch, of this
Image . |
void |
setXmpData(XmpPacketWrapper value)
Gets or sets XMP data from frame.
|
binarizeBradley, dither, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getModifyDate, getPixel, getRawCustomColorConverter, getRawDataFormat, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, isRawDataAvailable, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, readArgb32ScanLine, readScanLine, replaceColor, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setPalette, setPixel, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setTransparentColor, setUpdateXmpData, setUseRawData, toBitmap, writeArgb32ScanLine, writeScanLine
canLoad, canLoad, canLoad, canLoad, canSave, create, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getOriginalOptions, getPalette, getProgressEventHandler, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSize, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalette
getDataStreamContainer, save, save, save, save
close, dispose, getDisposed
public TiffImage(TiffFrame frame)
Initializes a new instance of the TiffImage
class.
frame
- The tiff frame to initialize image with.com.aspose.ms.System.ArgumentNullException
- Tiff frame cannot be empty.;frameThis example shows how to create a TIFF image from scratch and save it to a file.
String dir = "c:\\temp\\"; com.aspose.imaging.imageoptions.TiffOptions createOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); // Set 8 bits for each color component. createOptions.setBitsPerSample(new int[]{8, 8, 8}); // Set the Big Endian byte order (Motorola) createOptions.setByteOrder(com.aspose.imaging.fileformats.tiff.enums.TiffByteOrder.BigEndian); // Set the LZW compression. createOptions.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.Lzw); // Set the RGB color model. createOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); // All color components will be stored within a single plane. createOptions.setPlanarConfiguration(com.aspose.imaging.fileformats.tiff.enums.TiffPlanarConfigs.Contiguous); // Create a TIFF Frame of 100x100 px. // Note that you don't have to dispose a frame explicitly if it is included into TiffImage. // When the container is disposed all frames will be disposed automatically. com.aspose.imaging.fileformats.tiff.TiffFrame firstFrame = new com.aspose.imaging.fileformats.tiff.TiffFrame(createOptions, 100, 100); // Fill the entire frame with the blue-yellow gradient. com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(firstFrame.getWidth(), firstFrame.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getYellow()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(firstFrame); graphics.fillRectangle(gradientBrush, firstFrame.getBounds()); // Create a TIFF image. com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = new com.aspose.imaging.fileformats.tiff.TiffImage(firstFrame); try { tiffImage.save(dir + "output.tif"); } finally { tiffImage.dispose(); }
public TiffImage(TiffFrame[] frames)
Initializes a new instance of the TiffImage
class.
frames
- The frames.com.aspose.ms.System.ArgumentNullException
- framesThis example shows how to create a TIFF image with 2 frames and save it to a file.
String dir = "c:\\temp\\"; // Options for the first frame com.aspose.imaging.imageoptions.TiffOptions createOptions1 = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); // Set 8 bits for each color component. createOptions1.setBitsPerSample(new int[]{8, 8, 8}); // Set the Big Endian byte order (Motorola) createOptions1.setByteOrder(com.aspose.imaging.fileformats.tiff.enums.TiffByteOrder.BigEndian); // Set the LZW compression. createOptions1.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.Lzw); // Set the RGB color model. createOptions1.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); // All color components will be stored within a single plane. createOptions1.setPlanarConfiguration(com.aspose.imaging.fileformats.tiff.enums.TiffPlanarConfigs.Contiguous); // Create the first TIFF frame of 100x100 px. // Note that you don't have to dispose frames explicitly if they are included into TiffImage. // When the container is disposed all frames will be disposed automatically. com.aspose.imaging.fileformats.tiff.TiffFrame frame1 = new com.aspose.imaging.fileformats.tiff.TiffFrame(createOptions1, 100, 100); // Fill the first frame with the blue-yellow gradient. com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(frame1.getWidth(), frame1.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getYellow()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(frame1); graphics.fillRectangle(gradientBrush, frame1.getBounds()); // Options for the first frame com.aspose.imaging.imageoptions.TiffOptions createOptions2 = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); // Set 1 bit per pixel for a B/W image. createOptions2.setBitsPerSample(new int[]{1}); // Set the Little Endian byte order (Intel) createOptions2.setByteOrder(com.aspose.imaging.fileformats.tiff.enums.TiffByteOrder.LittleEndian); // Set the CCITT Group 3 Fax compression. createOptions2.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.CcittFax3); // Set the B/W color model where 0 is black, 1 is white. createOptions2.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.MinIsBlack); // Create the second TIFF frame of 200x200px. com.aspose.imaging.fileformats.tiff.TiffFrame frame2 = new com.aspose.imaging.fileformats.tiff.TiffFrame(createOptions2, 200, 200); // Fill the second frame with the blue-yellow gradient. // It will be automatically converted to the B/W format due to the corresponding settings of the frame. com.aspose.imaging.Graphics graphics2 = new com.aspose.imaging.Graphics(frame2); graphics2.fillRectangle(gradientBrush, frame2.getBounds()); // Create a TIFF image. com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = new com.aspose.imaging.fileformats.tiff.TiffImage( new com.aspose.imaging.fileformats.tiff.TiffFrame[]{frame1, frame2}); try { tiffImage.save(dir + "output.mutliframe.tif"); } finally { tiffImage.dispose(); }
public boolean hasAlpha()
Gets a value indicating whether this instance has alpha.
hasAlpha
in class RasterImage
true
if this instance has alpha; otherwise, false
.The following example loads a TIFF image and prints information about raw data format and alpha channel.
String dir = "c:\\temp\\"; String fileName = dir + "sample.tif"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // If the active TIFF frame has alpha channel, then the entire TIFF image is considered to have alpha channel. System.out.printf("ImageFile=%s, FileFormat=%s, HasAlpha=%s\r\n", fileName, tiffImage.getRawDataFormat(), tiffImage.hasAlpha()); int i = 0; for (com.aspose.imaging.fileformats.tiff.TiffFrame frame : tiffImage.getFrames()) { System.out.printf("Frame=%s, FileFormat=%s, HasAlpha=%s\r\n", ++i, frame.getRawDataFormat(), frame.hasAlpha()); } } finally { image.dispose(); } // The output may look like this: // ImageFile=c:\temp\sample.tif, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False // Frame=1, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False // Frame=2, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
public boolean hasTransparentColor()
Gets a value indicating whether image has transparent color.
hasTransparentColor
in class RasterImage
public void setTransparentColor(boolean value)
Gets a value indicating whether image has transparent color.
setTransparentColor
in class RasterImage
value
- a value indicating whether image has transparent color.public long getFileFormat()
Gets a value of file format
getFileFormat
in class Image
public boolean getPremultiplyComponents()
Gets or sets a value indicating whether components must be premultiplied.
getPremultiplyComponents
in class RasterImage
true
if components must be premultiplied; otherwise, false
.public void setPremultiplyComponents(boolean value)
Gets or sets a value indicating whether components must be premultiplied.
setPremultiplyComponents
in class RasterImage
value
- true
if components must be premultiplied; otherwise, false
.The following example creates a new TIFF 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.TiffOptions createOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.TiffDeflateRgba); createOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]), true)); com.aspose.imaging.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createOptions, imageWidth, imageHeight); try { // Save pixels for the whole image. image.savePixels(image.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; image.setPremultiplyComponents(true); com.aspose.imaging.Color[] premultipliedColors = image.loadPixels(image.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(); } //The output will look like this: //Original color: Color [A=127, R=255, G=0, B=0] //Premultiplied color: Color [A=127, R=127, G=0, B=0] //Original color: Color [A=127, R=0, G=255, B=0] //Premultiplied color: Color [A=127, R=0, G=127, B=0] //Original color: Color [A=127, R=0, G=0, B=255] //Premultiplied color: Color [A=127, R=0, G=0, B=127] //Original color: Color [A=127, R=255, G=255, B=0] //Premultiplied color: Color [A=127, R=127, G=127, B=0] //Original color: Color [A=127, R=255, G=0, B=255] //Premultiplied color: Color [A=127, R=127, G=0, B=127] //Original color: Color [A=127, R=0, G=255, B=255] //Premultiplied color: Color [A=127, R=0, G=127, B=127]
public int getByteOrder()
Gets or sets a value indicating the tiff byte order.
public void setByteOrder(int value)
Gets or sets a value indicating the tiff byte order.
value
- The tiff byte order.public double getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this Image
.
getHorizontalResolution
in class RasterImage
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.
The following example shows how to set horizontal/vertical resolution of a TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Get horizontal and vertical resolution of the TiffImage. double horizontalResolution = tiffImage.getHorizontalResolution(); double verticalResolution = tiffImage.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"); tiffImage.setResolution(96.0, 96.0); System.out.println("The horizontal resolution, in pixels per inch: " + tiffImage.getHorizontalResolution()); System.out.println("The vertical resolution, in pixels per inch: " + tiffImage.getVerticalResolution()); } } finally { image.dispose(); } // The output may look like this: // The horizontal resolution, in pixels per inch: 96.0 // The vertical resolution, in pixels per inch: 96.0
public void setHorizontalResolution(double value)
Gets the horizontal resolution, in pixels per inch, of this Image
.
setHorizontalResolution
in class RasterImage
value
- The horizontal resolution.
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
public double getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this Image
.
getVerticalResolution
in class RasterImage
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.
The following example shows how to set horizontal/vertical resolution of a TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Get horizontal and vertical resolution of the TiffImage. double horizontalResolution = tiffImage.getHorizontalResolution(); double verticalResolution = tiffImage.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"); tiffImage.setResolution(96.0, 96.0); System.out.println("The horizontal resolution, in pixels per inch: " + tiffImage.getHorizontalResolution()); System.out.println("The vertical resolution, in pixels per inch: " + tiffImage.getVerticalResolution()); } } finally { image.dispose(); } // The output may look like this: // The horizontal resolution, in pixels per inch: 96.0 // The vertical resolution, in pixels per inch: 96.0
public void setVerticalResolution(double value)
Gets the vertical resolution, in pixels per inch, of this Image
.
setVerticalResolution
in class RasterImage
value
- The vertical resolution.
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
public Color getBackgroundColor()
Gets or sets a value for the background color.
getBackgroundColor
in class Image
public void setBackgroundColor(Color value)
Gets or sets a value for the background color.
setBackgroundColor
in class Image
public int getBitsPerPixel()
Gets the image bits per pixel value of current frame.
getBitsPerPixel
in class Image
public TiffFrame getActiveFrame()
Gets or sets the active frame.
The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false)); createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); createTiffOptions.setBitsPerSample(new int[]{8, 8, 8}); com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100); try { // This is Font and Brush for drawing text on individual frames. com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite()); // Create 5 frames for (int i = 1; i <= 5; i++) { com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions(); createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]))); // Create a PNG image and draw the number of page on it. com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage); gr.drawString(Integer.toString(i), font, brush, 10, 10); // Create a frame based on the PNG image. com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage); // Add the frame to the TIFF image. tiffImage.addFrame(frame); } // The image was created with a single default frame. Let's remove it. com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame(); tiffImage.setActiveFrame(tiffImage.getFrames()[1]); tiffImage.removeFrame(0); // Don't forget to dispose the frame if you won't add it to some other TiffImage activeFrame.dispose(); tiffImage.save(); } finally { tiffImage.dispose(); }
public void setActiveFrame(TiffFrame value)
Gets or sets the active frame.
value
- Active frame.The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false)); createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); createTiffOptions.setBitsPerSample(new int[]{8, 8, 8}); com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100); try { // This is Font and Brush for drawing text on individual frames. com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite()); // Create 5 frames for (int i = 1; i <= 5; i++) { com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions(); createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]))); // Create a PNG image and draw the number of page on it. com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage); gr.drawString(Integer.toString(i), font, brush, 10, 10); // Create a frame based on the PNG image. com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage); // Add the frame to the TIFF image. tiffImage.addFrame(frame); } // The image was created with a single default frame. Let's remove it. com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame(); tiffImage.setActiveFrame(tiffImage.getFrames()[1]); tiffImage.removeFrame(0); // Don't forget to dispose the frame if you won't add it to some other TiffImage activeFrame.dispose(); tiffImage.save(); } finally { tiffImage.dispose(); }
public TiffFrame[] getFrames()
Gets Frames array of the image.
The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false)); createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); createTiffOptions.setBitsPerSample(new int[]{8, 8, 8}); com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100); try { // This is Font and Brush for drawing text on individual frames. com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite()); // Create 5 frames for (int i = 1; i <= 5; i++) { com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions(); createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]))); // Create a PNG image and draw the number of page on it. com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage); gr.drawString(Integer.toString(i), font, brush, 10, 10); // Create a frame based on the PNG image. com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage); // Add the frame to the TIFF image. tiffImage.addFrame(frame); } // The image was created with a single default frame. Let's remove it. com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame(); tiffImage.setActiveFrame(tiffImage.getFrames()[1]); tiffImage.removeFrame(0); // Don't forget to dispose the frame if you won't add it to some other TiffImage activeFrame.dispose(); tiffImage.save(); } finally { tiffImage.dispose(); }
public int getHeight()
Gets the image height.
getHeight
in interface IObjectWithBounds
getHeight
in class Image
public int getWidth()
Gets the image width.
getWidth
in interface IObjectWithBounds
getWidth
in class Image
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 ExifData getExifData()
Gets or sets EXIF data for the active frame.
public void setExifData(ExifData value)
Gets or sets EXIF data for the active frame.
public float getImageOpacity()
Gets opacity of this image (active frame).
getImageOpacity
in class RasterImage
public XmpPacketWrapper getXmpData()
Gets or sets XMP data from frame.
getXmpData
in class RasterImage
public void setXmpData(XmpPacketWrapper value)
Gets or sets XMP data from frame.
setXmpData
in class RasterImage
value
- XMP packet data wrapperpublic void alignResolutions()
Helper method to make horizontal and vertical resolutions equal.
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 TIFF 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.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) 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. tiffImage.dither(com.aspose.imaging.DitheringMethod.ThresholdDithering, 4, null); tiffImage.save(dir + "sample.ThresholdDithering4.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) 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. tiffImage.dither(com.aspose.imaging.DitheringMethod.FloydSteinbergDithering, 1, null); tiffImage.save(dir + "sample.FloydSteinbergDithering1.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void setResolution(double dpiX, double dpiY)
Sets the resolution for this RasterImage
.
setResolution
in class RasterImage
dpiX
- The horizontal resolution, in dots per inch, of the RasterImage
.dpiY
- The vertical resolution, in dots per inch, of the RasterImage
.The following example shows how to set horizontal/vertical resolution of a TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Get horizontal and vertical resolution of the TiffImage. double horizontalResolution = tiffImage.getHorizontalResolution(); double verticalResolution = tiffImage.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"); tiffImage.setResolution(96.0, 96.0); System.out.println("The horizontal resolution, in pixels per inch: " + tiffImage.getHorizontalResolution()); System.out.println("The vertical resolution, in pixels per inch: " + tiffImage.getVerticalResolution()); } } finally { image.dispose(); } // The output may look like this: // The horizontal resolution, in pixels per inch: 96.0 // The vertical resolution, in pixels per inch: 96.0
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 rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the Active frame only.
rotateFlip
in class Image
rotateFlipType
- The rotate flip type.This example loads a TIFF 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 Utils { // 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 Utils utils = new Utils(); 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.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { image.rotateFlip(rotateFlipType); image.save(dir + "sample." + utils.rotateFlipTypeToString(rotateFlipType) + ".png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } }
public void rotateFlipAll(int rotateFlip)
Rotates the flip all frames in image.
rotateFlip
- The rotate flip type.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.The following example shows how to rotate a TIFF image around the center by 45 degrees clockwise.
String dir = "c:\\temp\\"; com.aspose.imaging.imageoptions.TiffOptions createTiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); // Create a permanent, not temporary file source. createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dir + "rotated.tif", false)); createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); createTiffOptions.setBitsPerSample(new int[]{8, 8, 8}); com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100); try { // The linear gradient from the left-top to the right-bottom corner of the image. com.aspose.imaging.brushes.LinearGradientBrush brush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(tiffImage.getWidth(), tiffImage.getHeight()), com.aspose.imaging.Color.getRed(), com.aspose.imaging.Color.getGreen()); // Fill the active frame with the linear gradient brush. com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(tiffImage); gr.fillRectangle(brush, tiffImage.getBounds()); // Rotate the image around the center by 45 degrees clockwise. // The image size changed according to rotated rectangle (corner points). tiffImage.rotate(45f, true, com.aspose.imaging.Color.getBlack()); tiffImage.save(); // Rotate the image around the center by 45 degrees clockwise. // Leave the image dimensions untouched and only the internal image content are rotated. tiffImage.rotate(45f, false, com.aspose.imaging.Color.getGray()); tiffImage.save(dir + "rotated.preservesize.tif"); } finally { tiffImage.dispose(); }
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 addFrame(TiffFrame frame)
Adds the frame to image
frame
- The frame to add.The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false)); createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); createTiffOptions.setBitsPerSample(new int[]{8, 8, 8}); com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100); try { // This is Font and Brush for drawing text on individual frames. com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite()); // Create 5 frames for (int i = 1; i <= 5; i++) { com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions(); createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]))); // Create a PNG image and draw the number of page on it. com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage); gr.drawString(Integer.toString(i), font, brush, 10, 10); // Create a frame based on the PNG image. com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage); // Add the frame to the TIFF image. tiffImage.addFrame(frame); } // The image was created with a single default frame. Let's remove it. com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame(); tiffImage.setActiveFrame(tiffImage.getFrames()[1]); tiffImage.removeFrame(0); // Don't forget to dispose the frame if you won't add it to some other TiffImage activeFrame.dispose(); tiffImage.save(); } finally { tiffImage.dispose(); }
public void add(TiffImage image)
Adds the specified image's frames to current frame.
image
- The source image.public void addFrames(TiffFrame[] frames)
Adds the frames array to image
frames
- The frames array to addpublic void insertFrame(int index, TiffFrame frameToInsert)
The insert frame.
index
- Index of new frame in list of framesframeToInsert
- The frame To Insert.public final TiffFrame replaceFrame(int index, TiffFrame frameToReplace)
Replaces the frame at the specified position.
index
- The zero based frame position.frameToReplace
- The frame to replace.
public TiffFrame removeFrame(int index)
Removes the frame by its index.
index
- Index of frame to be removed.
Note: do not forget to Dispose the frame if you will not add it to some other TiffImage.
The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false)); createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb); createTiffOptions.setBitsPerSample(new int[]{8, 8, 8}); com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100); try { // This is Font and Brush for drawing text on individual frames. com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64); com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite()); // Create 5 frames for (int i = 1; i <= 5; i++) { com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions(); createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]))); // Create a PNG image and draw the number of page on it. com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100); com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage); gr.drawString(Integer.toString(i), font, brush, 10, 10); // Create a frame based on the PNG image. com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage); // Add the frame to the TIFF image. tiffImage.addFrame(frame); } // The image was created with a single default frame. Let's remove it. com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame(); tiffImage.setActiveFrame(tiffImage.getFrames()[1]); tiffImage.removeFrame(0); // Don't forget to dispose the frame if you won't add it to some other TiffImage activeFrame.dispose(); tiffImage.save(); } finally { tiffImage.dispose(); }
public void removeFrame(TiffFrame frame)
Removes the specified frame.
frame
- The frame to remove.
Note: do not forget to Dispose the frame if you will not add it to some other TiffImage.
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 TIFF image and resizes it using various resizing methods.
String dir = "c:\\temp\\"; com.aspose.imaging.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); 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.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); 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.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); 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.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); 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 TIFF 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) com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Scale down by 2 times using adaptive resampling. tiffImage.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings); // Save to PNG tiffImage.save(dir + "downsample.adaptive.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void resizeWidthProportionally(int newWidth, int resizeType)
Resizes the width proportionally.
resizeWidthProportionally
in class Image
newWidth
- The new width.resizeType
- Type of the resize.This example loads a TIFF image and resizes it proportionally using various resizing methods. Only the width is specified, the height is calculated automatically.
String dir = "c:\\temp\\"; com.aspose.imaging.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale up by 2 times using Nearest Neighbour resampling. image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); // Save to PNG with the default options. image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale down by 2 times using Nearest Neighbour resampling. image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); // Save to PNG with the default options. image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale up by 2 times using Bilinear resampling. image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.BilinearResample); // Save to PNG with the default options. image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale down by 2 times using Bilinear resampling. image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.BilinearResample); // Save to PNG with the default options. image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void resizeHeightProportionally(int newHeight, int resizeType)
Resizes the height proportionally.
resizeHeightProportionally
in class Image
newHeight
- The new height.resizeType
- Type of the resize.This example loads a TIFF image and resizes it proportionally using various resizing methods. Only the height is specified, the width is calculated automatically.
String dir = "c:\\temp\\"; com.aspose.imaging.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale up by 2 times using Nearest Neighbour resampling. image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); // Save to PNG with the default options. image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale down by 2 times using Nearest Neighbour resampling. image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample); // Save to PNG with the default options. image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale up by 2 times using Bilinear resampling. image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample); // Save to PNG with the default options. image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif"); try { // Scale down by 2 times using Bilinear resampling. image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample); // Save to PNG with the default options. image.save(dir + "downsample.bilinear.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 TIFF 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.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) 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( tiffImage.getWidth() / 4, tiffImage.getHeight() / 4, tiffImage.getWidth() / 2, tiffImage.getHeight() / 2); tiffImage.crop(area); // Save the cropped image to PNG tiffImage.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 TIFF 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.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; tiffImage.grayscale(); tiffImage.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 TIFF 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.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) 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. tiffImage.binarizeFixed((byte) 127); tiffImage.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 TIFF 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.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Binarize the image with Otsu thresholding. tiffImage.binarizeOtsu(); tiffImage.save(dir + "sample.BinarizeOtsu.png", new com.aspose.imaging.imageoptions.PngOptions()); } 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 TIFF 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.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) 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. tiffImage.binarizeBradley(5, 10); tiffImage.save(dir + "sample.BinarizeBradley5_10x10.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); }
public void crop(int leftShift, int rightShift, int topShift, int bottomShift)
Crop image with shifts.
crop
in class RasterImage
leftShift
- The left shift.rightShift
- The right shift.topShift
- The top shift.bottomShift
- The bottom shift.The following example crops a TIFF image. The cropping area is specified via Left, Top, Right, Bottom margins.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Crop again. Set a margin of 10% of the image size. int horizontalMargin = tiffImage.getWidth() / 10; int verticalMargin = tiffImage.getHeight() / 10; tiffImage.crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin); // Save the cropped image to PNG. tiffImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions()); } 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 TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Set the brightness value. The accepted values of brightness are in the range [-255, 255]. tiffImage.adjustBrightness(50); tiffImage.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 TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Set the contrast value. The accepted values of contrast are in the range [-100f, 100f]. tiffImage.adjustContrast(50f); tiffImage.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 TIFF image applying different coefficients for color components.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Set individual gamma coefficients for red, green and blue channels. tiffImage.adjustGamma(1.5f, 2.5f, 3.5f); tiffImage.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 TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Set gamma coefficient for red, green and blue channels. tiffImage.adjustGamma(2.5f); tiffImage.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 TIFF image.
String dir = "c:\\temp\\"; com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Apply a median filter with a rectangle size of 5 to the entire image. tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(5)); tiffImage.save(dir + "sample.MedianFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Apply a bilateral smoothing filter with a kernel size of 5 to the entire image. tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(5)); tiffImage.save(dir + "sample.BilateralSmoothingFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image. tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions(5, 4.0)); tiffImage.save(dir + "sample.GaussianBlurFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image. tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussWienerFilterOptions(5, 4.0)); tiffImage.save(dir + "sample.GaussWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) 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. tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MotionWienerFilterOptions(10, 1.0, 90.0)); tiffImage.save(dir + "sample.MotionWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions()); } finally { image.dispose(); } image = com.aspose.imaging.Image.load(dir + "sample.tif"); try { com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image; // Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image. tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions(5, 4.0)); tiffImage.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.