public final class TiffFrame extends RasterCachedImage
The tiff frame.
This 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(); }
Constructor and Description |
---|
TiffFrame(InputStream stream)
Initializes a new instance of the
TiffFrame class. |
TiffFrame(InputStream stream,
TiffOptions options)
Initializes a new instance of the
TiffFrame class. |
TiffFrame(RasterImage image)
Initializes a new instance of the
TiffFrame class. |
TiffFrame(RasterImage image,
TiffOptions options)
Initializes a new instance of the
TiffFrame class. |
TiffFrame(String path)
Initializes a new instance of the
TiffFrame class. |
TiffFrame(String path,
TiffOptions options)
Initializes a new instance of the
TiffFrame class. |
TiffFrame(TiffOptions options,
int width,
int height)
Initializes a new instance of the
TiffFrame class. |
Modifier and Type | Method and Description |
---|---|
void |
alignResolutions()
Helper method to make horizontal and vertical resolutions equal.
|
static TiffFrame |
copyFrame(TiffFrame tiffFrame)
Copies the entire frame (duplicates).
|
static TiffFrame |
createFrameFrom(TiffFrame tiffFrame,
TiffOptions options)
Creates the frame from specified
tiffFrame using the specified options . |
Color |
getBackgroundColor()
Gets a value for the background color.
|
int |
getBitsPerPixel()
Gets the image bits per pixel count.
|
ExifData |
getExifData()
Gets EXIF data from frame.
|
TiffOptions |
getFrameOptions()
Gets the frame create options.
|
int |
getHeight()
Gets the image height.
|
double |
getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this
RasterImage . |
double |
getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this
RasterImage . |
int |
getWidth()
Gets the image width.
|
XmpPacketWrapper |
getXmpData()
Gets XMP data from frame.
|
boolean |
hasAlpha()
Gets a value indicating whether this instance has alpha.
|
boolean |
hasTransparentColor()
Gets a value indicating whether image has transparent color.
|
void |
setBackgroundColor(Color value)
Sets a value for the background color.
|
void |
setExifData(ExifData value)
Sets EXIF data from frame.
|
void |
setHorizontalResolution(double value)
Sets the horizontal resolution, in pixels per inch, of this
RasterImage . |
void |
setTransparentColor(boolean value)
Gets a value indicating whether image has transparent color.
|
void |
setVerticalResolution(double value)
Sets the vertical resolution, in pixels per inch, of this
RasterImage . |
void |
setXmpData(XmpPacketWrapper value)
Sets XMP data from frame.
|
adjustBrightness, adjustContrast, adjustGamma, adjustGamma, binarizeBradley, binarizeBradley, binarizeFixed, binarizeOtsu, cacheData, crop, dither, grayscale, isCached, resize, resize, rotate, rotateFlip
crop, dither, filter, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getImageOpacity, getModifyDate, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataFormat, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, 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, setPalette, setPixel, setPremultiplyComponents, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setResolution, setTransparentColor, setUpdateXmpData, setUseRawData, toBitmap, writeArgb32ScanLine, writeScanLine
canLoad, canLoad, canLoad, canLoad, canSave, create, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getOriginalOptions, getPalette, getProgressEventHandler, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSize, hasBackgroundColor, 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 TiffFrame(InputStream stream)
Initializes a new instance of the TiffFrame
class.
stream
- The stream to load an image from and initialize frame pixel and palette data with.public TiffFrame(InputStream stream, TiffOptions options)
Initializes a new instance of the TiffFrame
class.
stream
- The stream to load an image from and initialize frame pixel and palette data with.options
- The options to use for the newly created frame.public TiffFrame(String path)
Initializes a new instance of the TiffFrame
class.
path
- The path to load an image from and initialize frame pixel and palette data with.public TiffFrame(String path, TiffOptions options)
Initializes a new instance of the TiffFrame
class.
path
- The path to load an image from and initialize frame pixel and palette data with.options
- The options to use for the newly created frame.public TiffFrame(RasterImage image)
Initializes a new instance of the TiffFrame
class.
image
- The image to initialize frame pixel and palette data with.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(RasterImage image, TiffOptions options)
Initializes a new instance of the TiffFrame
class.
image
- The image to initialize frame pixel and palette data with.options
- The options to use for the newly created frame.public TiffFrame(TiffOptions options, int width, int height)
Initializes a new instance of the TiffFrame
class.
options
- The frame options.width
- The width.height
- The height.com.aspose.ms.System.ArgumentNullException
- Options parameter is null.This 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 Color getBackgroundColor()
Gets a value for the background color.
getBackgroundColor
in class Image
public void setBackgroundColor(Color value)
Sets a value for the background color.
setBackgroundColor
in class Image
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
public XmpPacketWrapper getXmpData()
Gets XMP data from frame.
getXmpData
in class RasterImage
public void setXmpData(XmpPacketWrapper value)
Sets XMP data from frame.
setXmpData
in class RasterImage
value
- XMP packet data wrapperpublic int getBitsPerPixel()
Gets the image bits per pixel count.
getBitsPerPixel
in class Image
public TiffOptions getFrameOptions()
Gets the frame create options.
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 ExifData getExifData()
Gets EXIF data from frame.
public void setExifData(ExifData value)
Sets EXIF data from frame.
value
- EXIF data containerpublic double getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this RasterImage
.
getHorizontalResolution
in class RasterImage
The following example shows how to set horizontal/vertical resolution of a separate TIFF frame.
String dir = "c:\\temp\\"; // Load a TIFF image from a file. 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; int i = 0; for (com.aspose.imaging.fileformats.tiff.TiffFrame frame : tiffImage.getFrames()) { // Get horizontal and vertical resolution of the TiffFrame. double horizontalResolution = frame.getHorizontalResolution(); double verticalResolution = frame.getVerticalResolution(); System.out.printf("The horizontal resolution of frame %s, pixels per inch: %s\r\n", i, horizontalResolution); System.out.printf("The vertical resolution, of frame %s, pixels per inch: %s\r\n", i, 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"); frame.setResolution(96.0, 96.0); System.out.printf("The horizontal resolution of frame %s, pixels per inch: %s\r\n", i, horizontalResolution); System.out.printf("The vertical resolution, of frame %s, pixels per inch: %s\r\n", i, verticalResolution); } ++i; } } finally { image.dispose(); }
public void setHorizontalResolution(double value)
Sets the horizontal resolution, in pixels per inch, of this RasterImage
.
setHorizontalResolution
in class RasterImage
value
- The horizontal resolution.public double getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this RasterImage
.
getVerticalResolution
in class RasterImage
The following example shows how to set horizontal/vertical resolution of a separate TIFF frame.
String dir = "c:\\temp\\"; // Load a TIFF image from a file. 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; int i = 0; for (com.aspose.imaging.fileformats.tiff.TiffFrame frame : tiffImage.getFrames()) { // Get horizontal and vertical resolution of the TiffFrame. double horizontalResolution = frame.getHorizontalResolution(); double verticalResolution = frame.getVerticalResolution(); System.out.printf("The horizontal resolution of frame %s, pixels per inch: %s\r\n", i, horizontalResolution); System.out.printf("The vertical resolution, of frame %s, pixels per inch: %s\r\n", i, 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"); frame.setResolution(96.0, 96.0); System.out.printf("The horizontal resolution of frame %s, pixels per inch: %s\r\n", i, horizontalResolution); System.out.printf("The vertical resolution, of frame %s, pixels per inch: %s\r\n", i, verticalResolution); } ++i; } } finally { image.dispose(); }
public void setVerticalResolution(double value)
Sets the vertical resolution, in pixels per inch, of this RasterImage
.
setVerticalResolution
in class RasterImage
value
- The vertical resolution.public void alignResolutions()
Helper method to make horizontal and vertical resolutions equal.
public static TiffFrame copyFrame(TiffFrame tiffFrame)
Copies the entire frame (duplicates).
tiffFrame
- The tiff frame to copy.public static TiffFrame createFrameFrom(TiffFrame tiffFrame, TiffOptions options)
Creates the frame from specified tiffFrame
using the specified options
.
The pixel data is preserved but converted to the desired format.
tiffFrame
- The tiff frame to create from.options
- The new options to use.The following example shows how to create a grayscale copy of an existing frame and add it to a TIFF image.
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 + "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 { // 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 a linear gradient brush. com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(tiffImage.getActiveFrame()); gr.fillRectangle(brush, tiffImage.getBounds()); // Grayscale options com.aspose.imaging.imageoptions.TiffOptions createTiffFrameOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default); createTiffFrameOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]))); createTiffFrameOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.MinIsBlack); createTiffFrameOptions.setBitsPerSample(new int[]{8}); // Create a grayscale copy of the active frame. // The pixel data is preserved but converted to the desired format. com.aspose.imaging.fileformats.tiff.TiffFrame grayscaleFrame = com.aspose.imaging.fileformats.tiff.TiffFrame.createFrameFrom(tiffImage.getActiveFrame(), createTiffFrameOptions); // Add the newly created frame to the TIFF image. tiffImage.addFrame(grayscaleFrame); tiffImage.save(); } finally { tiffImage.dispose(); }