TiffFrame
Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter, com.aspose.imaging.Image, com.aspose.imaging.RasterImage, com.aspose.imaging.RasterCachedImage
All Implemented Interfaces: com.aspose.internal.IMetadataContainer
public final class TiffFrame extends RasterCachedImage implements IMetadataContainer
The tiff frame.
Constructors
Constructor | 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(String path) | Initializes a new instance of the TiffFrame class. |
TiffFrame(String path, 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(TiffOptions options, int width, int height) | Initializes a new instance of the TiffFrame class. |
Methods
Method | Description |
---|---|
getBackgroundColor() | Gets a value for the background color. |
setBackgroundColor(Color value) | Sets a value for the background color. |
hasAlpha() | Gets a value indicating whether this instance has alpha. |
hasTransparentColor() | Gets a value indicating whether image has transparent color. |
setTransparentColor(boolean value) | Gets a value indicating whether image has transparent color. |
getXmpData() | Gets Xmp data. |
setXmpData(XmpPacketWrapper value) | Sets Xmp data. |
getBitsPerPixel() | Gets the image bits per pixel count. |
getFrameOptions() | Gets the frame create options. |
getHeight() | Gets the image height. |
getWidth() | Gets the image width. |
getExifData() | Gets EXIF data from frame. |
setExifData(ExifData value) | Sets EXIF data from frame. |
getHorizontalResolution() | Gets the horizontal resolution, in pixels per inch, of this RasterImage . |
setHorizontalResolution(double value) | Sets the horizontal resolution, in pixels per inch, of this RasterImage . |
getVerticalResolution() | Gets the vertical resolution, in pixels per inch, of this RasterImage . |
setVerticalResolution(double value) | Sets the vertical resolution, in pixels per inch, of this RasterImage . |
getPathResources() | Gets the path resources. |
setPathResources(List | Sets the path resources. |
removeMetadata() | Removes this image instance metadata by setting this IHasXmpData.XmpData (IHasXmpData.getXmpData/IHasXmpData.setXmpData(XmpPacketWrapper)) and IHasExifData.ExifData (IHasExifData.getExifData/IHasExifData.setExifData(ExifData) IHasExifData.setExifData) values to null . |
getOriginalOptions() | Gets the options based on the original file settings. |
alignResolutions() | Helper method to make horizontal and vertical resolutions equal. |
copyFrame(TiffFrame tiffFrame) | Copies the entire frame (duplicates). |
createFrameFrom(TiffFrame tiffFrame, TiffOptions options) | Creates the frame from specified tiffFrame using the specified options . |
resize(int newWidth, int newHeight, int resizeType) | Resizes the image. |
rotate(float angle, boolean resizeProportionally, Color backgroundColor) | Rotate image around the center. |
crop(Rectangle rectangle) | Cropping the image. |
Example: 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();
}
TiffFrame(InputStream stream)
public TiffFrame(InputStream stream)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | The stream to load an image from and initialize frame pixel and palette data with. |
TiffFrame(InputStream stream, TiffOptions options)
public TiffFrame(InputStream stream, TiffOptions options)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | The stream to load an image from and initialize frame pixel and palette data with. |
options | TiffOptions | The options to use for the newly created frame. |
TiffFrame(String path)
public TiffFrame(String path)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | The path to load an image from and initialize frame pixel and palette data with. |
TiffFrame(String path, TiffOptions options)
public TiffFrame(String path, TiffOptions options)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | The path to load an image from and initialize frame pixel and palette data with. |
options | TiffOptions | The options to use for the newly created frame. |
TiffFrame(RasterImage image)
public TiffFrame(RasterImage image)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | The image to initialize frame pixel and palette data with. |
TiffFrame(RasterImage image, TiffOptions options)
public TiffFrame(RasterImage image, TiffOptions options)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
image | RasterImage | The image to initialize frame pixel and palette data with. |
options | TiffOptions | The options to use for the newly created frame. |
TiffFrame(TiffOptions options, int width, int height)
public TiffFrame(TiffOptions options, int width, int height)
Initializes a new instance of the TiffFrame
class.
Parameters:
Parameter | Type | Description |
---|---|---|
options | TiffOptions | The frame options. |
width | int | The width. |
height | int | The height. |
getBackgroundColor()
public Color getBackgroundColor()
Gets a value for the background color.
Returns: Color
setBackgroundColor(Color value)
public void setBackgroundColor(Color value)
Sets a value for the background color.
Parameters:
Parameter | Type | Description |
---|---|---|
value | Color |
hasAlpha()
public boolean hasAlpha()
Gets a value indicating whether this instance has alpha.
Returns:
boolean - true
if this instance has alpha; otherwise, false
.
Example: 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
hasTransparentColor()
public boolean hasTransparentColor()
Gets a value indicating whether image has transparent color.
Returns: boolean
setTransparentColor(boolean value)
public void setTransparentColor(boolean value)
Gets a value indicating whether image has transparent color.
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean |
getXmpData()
public XmpPacketWrapper getXmpData()
Gets Xmp data.
Returns: XmpPacketWrapper - Xmp data.
setXmpData(XmpPacketWrapper value)
public void setXmpData(XmpPacketWrapper value)
Sets Xmp data.
Parameters:
Parameter | Type | Description |
---|---|---|
value | XmpPacketWrapper | Xmp data. |
getBitsPerPixel()
public int getBitsPerPixel()
Gets the image bits per pixel count.
Returns: int - The image bits per pixel count.
getFrameOptions()
public TiffOptions getFrameOptions()
Gets the frame create options.
Returns: TiffOptions
getHeight()
public int getHeight()
Gets the image height.
Returns: int - The image height.
getWidth()
public int getWidth()
Gets the image width.
Returns: int - The image width.
getExifData()
public ExifData getExifData()
Gets EXIF data from frame.
Returns: ExifData - EXIF data container
setExifData(ExifData value)
public void setExifData(ExifData value)
Sets EXIF data from frame.
Parameters:
Parameter | Type | Description |
---|---|---|
value | ExifData | EXIF data container |
getHorizontalResolution()
public double getHorizontalResolution()
Gets the horizontal resolution, in pixels per inch, of this RasterImage
.
Returns: double - The horizontal resolution.
Example: 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();
}
setHorizontalResolution(double value)
public void setHorizontalResolution(double value)
Sets the horizontal resolution, in pixels per inch, of this RasterImage
.
Parameters:
Parameter | Type | Description |
---|---|---|
value | double | The horizontal resolution. |
getVerticalResolution()
public double getVerticalResolution()
Gets the vertical resolution, in pixels per inch, of this RasterImage
.
Returns: double - The vertical resolution.
Example: 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();
}
setVerticalResolution(double value)
public void setVerticalResolution(double value)
Sets the vertical resolution, in pixels per inch, of this RasterImage
.
Parameters:
Parameter | Type | Description |
---|---|---|
value | double | The vertical resolution. |
getPathResources()
public List<PathResource> getPathResources()
Gets the path resources.
Value: The path resources.
Returns: java.util.List<com.aspose.imaging.fileformats.tiff.pathresources.PathResource> - the path resources.
Example: The following example shows how to retrieve paths from TIFF image and display their names in the console.
try (TiffImage image = (TiffImage) Image.load("Sample.tif"))
{
for (PathResource path : image.getActiveFrame().getPathResources())
{
System.out.println(path.getName());
}
}
Example: The following example shows how to modify already existing Clipping Paths. The following example shows how to modify already existing Clipping Paths. For instance, you can keep only one Clipping Path in the image.
try (TiffImage image = (TiffImage) Image.load("Sample.tif"))
{
List<PathResource> paths = image.getActiveFrame().getPathResources();
image.getActiveFrame().setPathResources(Collections.singletonList(paths.get(0)));
image.save();
}
Example: Transfer Clipping Paths during export from TIFF to PSD image.
try (Image image = Image.load("Sample.tif"))
{
image.save("SampleWithPaths.psd", new PsdOptions());
}
Example: Create Clipping Path manually.
static void main()
{
try (TiffImage image = (TiffImage)Image.load("Sample.tif"))
{
PathResource res = new PathResource();
res.setBlockId((short) 2000); // Block Id according to Photoshop specification
res.setName("My Clipping Path"); // Path name
res.setRecords(createRecords(0.2f, 0.2f, 0.8f, 0.2f, 0.8f, 0.8f, 0.2f, 0.8f)); // Create path records using coordinates
image.getActiveFrame().setPathResources(Collections.singletonList(res));
image.save("ImageWithPath.tif");
}
}
private static List<VectorPathRecord> createRecords(float ... coordinates)
{
List<VectorPathRecord> records = createBezierRecords(coordinates); // Create Bezier records using coordinates
LengthRecord lr = new LengthRecord(); // LengthRecord required by Photoshop specification
lr.setOpen(false); // Lets create closed path
lr.setRecordCount(records.size()); // Record count in the path
records.add(0, lr);
return records;
}
private static List<VectorPathRecord> createBezierRecords(float[] coordinates)
{
List<VectorPathRecord> l = new LinkedList<VectorPathRecord>();
for (int index = 0; index < coordinates.length - 1; index += 2)
{
PointF pt = new PointF(coordinates[index], coordinates[index + 1]);
BezierKnotRecord br = new BezierKnotRecord();
br.setPathPoints(new PointF[] {pt, pt, pt});
l.add(br);
}
return l;
}
setPathResources(List value)
public void setPathResources(List<PathResource> value)
Sets the path resources.
Value: The path resources.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.util.List<com.aspose.imaging.fileformats.tiff.pathresources.PathResource> | the path resources. |
removeMetadata()
public void removeMetadata()
Removes this image instance metadata by setting this IHasXmpData.XmpData (IHasXmpData.getXmpData/IHasXmpData.setXmpData(XmpPacketWrapper)) and IHasExifData.ExifData
(IHasExifData.getExifData/IHasExifData.setExifData(ExifData) IHasExifData.setExifData) values to null
.
getOriginalOptions()
public ImageOptionsBase getOriginalOptions()
Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the DataStreamSupporter.save(String) method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Image.save(String, ImageOptionsBase) method as the second parameter.
Returns: ImageOptionsBase - The options based on the original file settings.
alignResolutions()
public void alignResolutions()
Helper method to make horizontal and vertical resolutions equal.
copyFrame(TiffFrame tiffFrame)
public static TiffFrame copyFrame(TiffFrame tiffFrame)
Copies the entire frame (duplicates).
Parameters:
Parameter | Type | Description |
---|---|---|
tiffFrame | TiffFrame | The tiff frame to copy. |
Returns: TiffFrame - The newly copied tiff frame.
createFrameFrom(TiffFrame tiffFrame, TiffOptions options)
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.
Parameters:
Parameter | Type | Description |
---|---|---|
tiffFrame | TiffFrame | The tiff frame to create from. |
options | TiffOptions | The new options to use. |
Returns: TiffFrame - The newly created frame.
Example: 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();
}
resize(int newWidth, int newHeight, int resizeType)
public void resize(int newWidth, int newHeight, int resizeType)
Resizes the image.
Parameters:
Parameter | Type | Description |
---|---|---|
newWidth | int | The new width. |
newHeight | int | The new height. |
resizeType | int | The resize type. |
rotate(float angle, boolean resizeProportionally, Color backgroundColor)
public void rotate(float angle, boolean resizeProportionally, Color backgroundColor)
Rotate image around the center.
Parameters:
Parameter | Type | Description |
---|---|---|
angle | float | The rotation angle in degrees. Positive values will rotate clockwise. |
resizeProportionally | boolean | 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 | Color of the background. |
crop(Rectangle rectangle)
public void crop(Rectangle rectangle)
Cropping the image.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle. |