TiffImage

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter, com.aspose.imaging.Image, com.aspose.imaging.RasterImage, com.aspose.imaging.RasterCachedImage, com.aspose.imaging.RasterCachedMultipageImage

All Implemented Interfaces: com.aspose.imaging.IMultipageImageExt, com.aspose.imaging.IMetadataContainer

public class TiffImage extends RasterCachedMultipageImage implements IMultipageImageExt, IMetadataContainer

使用我们的 API 处理标记图像文件格式(TIFF)光栅图像,提供对各种分辨率的全面支持以及诸如 EXIF 数据操作和 Alpha 通道等高级编辑功能。对扫描图像进行角度归一化、调整大小、转换为灰度,并轻松应用滤镜、伽马校正和图像参数调整。无缝处理多帧 TIFF 文件,创建图形路径、添加形状,并轻松将图像保存为不同格式。

构造函数

构造函数描述
TiffImage(TiffFrame frame)初始化 TiffImage 类的新对象,指定 frame 参数。
TiffImage(TiffFrame[] frames)创建 TiffImage 类的新实例,提供帧列表作为参数。

方法

方法描述
getFileFormat()检索与图像关联的文件格式值。
getPremultiplyComponents()指示组件是否需要预乘,以确保对视觉元素的高效处理。
setPremultiplyComponents(boolean value)指示组件是否需要预乘,以确保对视觉元素的高效处理。
getByteOrder()无缝切换 TIFF 文件的字节序,确保对数据解释的精确控制。
setByteOrder(int value)无缝切换 TIFF 文件的字节序,确保对数据解释的精确控制。
getHorizontalResolution()检索指定 Image 的水平分辨率(每英寸像素),以便进行精确的调整和渲染功能。
setHorizontalResolution(double value)修改指定 Image 的水平分辨率(每英寸像素),以便进行精确的调整和渲染功能。
getVerticalResolution()访问指定 Image 的垂直分辨率(每英寸像素),实现精确的调整和渲染优化。
setVerticalResolution(double value)访问指定 Image 的垂直分辨率(每英寸像素),实现精确的调整和渲染优化。
getActiveFrame()无缝管理活动帧,便于在指定上下文中进行动态导航和操作。
setActiveFrame(TiffFrame value)无缝管理活动帧,便于在指定上下文中进行动态导航和操作。
getFrames()检索 TiffFrame 实例数组,以实现对 TIFF 图像中各个帧的全面访问和操作。
getPageCount()检索指定文档的页面总数,以便高效地导航和管理多页内容。
getPages()无缝访问文档的页面,实现内容结构中的动态导航和操作。
hasAlpha()确定图像是否具有 Alpha 通道,为渲染和合成操作提供关键信息。
removeMetadata()通过将此 IHasXmpData.XmpData(IHasXmpData.getXmpData/IHasXmpData.setXmpData(XmpPacketWrapper)) 的值设为 null,移除此图像实例的元数据。
getOriginalOptions()检索源文件设置派生的选项,以便无缝保留关键参数,如位深度以及原始图像的其他重要属性。
addPage(RasterImage page)无缝将新页面合并到现有图像中,扩展其内容和多功能性。
alignResolutions()实现 AlignResolutions 辅助方法,以同步水平和垂直分辨率,确保图像尺寸的一致性。
setResolution(double dpiX, double dpiY)为指定的 RasterImage 设置分辨率,实现对图像渲染和显示属性的精确控制。
normalizeAngle(boolean resizeProportionally, Color backgroundColor)利用专为扫描文本文件设计的 NormalizeAngle 方法来校正倾斜的扫描,确保准确对齐。
addFrame(TiffFrame frame)将指定的帧无缝合并到图像中,扩展其内容和多功能性。
add(TiffImage image)将指定图像中的帧无缝添加到当前帧中,整合其内容并提升构图灵活性。
addFrames(TiffFrame[] frames)将帧数组无缝集成到图像中,丰富其内容和多功能性。
insertFrame(int index, TiffFrame frame)在帧序列中的指定索引处插入新帧,确保对帧排列的精确控制。
replaceFrame(int index, TiffFrame newFrame)在指定位置将帧无缝替换为另一帧,便于在图像序列中进行动态帧管理。
removeFrame(int index)轻松删除图像序列中通过索引标识的帧,简化应用程序中的帧管理。
removeFrame(TiffFrame frame)高效移除图像序列中的指定帧,促进应用程序中简化的帧管理。
resizeProportional(int newWidth, int newHeight, int resizeType)对图像执行比例缩放操作,保持宽高比的同时调整其尺寸。
resizeWidthProportionally(int newWidth, int resizeType)在保持宽高比的前提下调整图像宽度,确保比例缩放以获得最佳视觉呈现。
resizeHeightProportionally(int newHeight, int resizeType)对图像高度进行比例调整,保持宽高比以确保视觉一致性。
rotateFlip(int rotateFlipType)仅在活动帧上执行旋转、翻转或两者的组合操作。
dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)对当前图像执行抖动处理,以提升视觉质量并减少颜色条纹伪影。
crop(Rectangle rectangle)使用指定的矩形区域裁剪图像,允许精确选择所需内容。
crop(int leftShift, int rightShift, int topShift, int bottomShift)通过指定左、右、上、下方向的位移来对图像进行裁剪。
binarizeFixed(byte threshold)使用预定义阈值对图像进行二值化,将其转换为前景和背景区域明确的二进制图像。
binarizeOtsu()利用 Otsu 阈值法对图像进行二值化,自动根据图像直方图确定最佳阈值。
binarizeBradley(double brightnessDifference, int windowSize)使用 Bradley 自适应阈值算法结合积分图阈值,对图像实现二值化。
grayscale()将图像转换为灰度表示,转化为单通道图像,每个像素表示强度。
adjustGamma(float gamma)对图像应用伽马校正,调整像素强度以实现所需的色彩平衡。
adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)使用红、绿、蓝通道的单独系数对图像进行伽马校正,允许对色彩平衡和对比度进行精细调整。
adjustBrightness(int brightness)实现对图像的 brightness 调整,允许修改整体亮度水平。
adjustContrast(float contrast)增强 Image 实例的对比度,放大其明暗区域之间的差异。
filter(Rectangle rectangle, FilterOptionsBase options)对指定矩形内的内容进行滤波,应用指定的图像处理滤镜以增强或修改所选区域。
resize(int newWidth, int newHeight, ImageResizeSettings settings)根据指定设置调整图像大小,允许对尺寸、宽高比和缩放行为进行精确控制。

Example: Create Graphics Path from Path Resources in TIFF image.

try (TiffImage image = (TiffImage)Image.load("Bottle.tif"))
{
    // 使用来自 TIFF 图像的 PathResources 创建 GraphicsPath
    GraphicsPath graphicsPath = PathResourceConverter.toGraphicsPath(
            image.getActiveFrame().getPathResources().toArray(new PathResource[0]), 
            image.getActiveFrame().getSize());
    Graphics graphics = new Graphics(image);

    // 绘制红色线条并保存图像
    graphics.drawPath(new Pen(Color.getRed(), 10), graphicsPath);
    image.save("BottleWithRedBorder.tif");
}

Example: Create Path Resources using Graphics Path.

static void main()
{
    try (TiffImage image = (TiffImage)Image.load("Bottle.tif"))
    {
        // 为 GraphicsPath 创建矩形 Figure
        Figure figure = new Figure();
        figure.addShape(createBezierShape(100f, 100f, 500f, 100f, 500f, 1000f, 100f, 1000f));

        // 使用我们的 Figure 创建 GraphicsPath
        GraphicsPath graphicsPath = new GraphicsPath();
        graphicsPath.addFigure(figure);

        // 使用 GraphicsPath 设置 PathResources
        PathResource[] pathResource = PathResourceConverter.fromGraphicsPath(graphicsPath, image.getSize());
        image.getActiveFrame().setPathResources(Arrays.asList(pathResource));

        // 保存图像
        image.save("BottleWithRectanglePath.tif");
    }
}

private static BezierShape createBezierShape(float ... coordinates)
{
    PointF[] bezierPoints = coordinatesToBezierPoints(coordinates);
    return new BezierShape(bezierPoints, true);
}

private static PointF[] coordinatesToBezierPoints(float[] coordinates)
{
    PointF[] bezierPoints = new PointF[3 * coordinates.length / 2];
    int i = 0;
    for (int coordinateIndex = 0; coordinateIndex < coordinates.length - 1; coordinateIndex += 2)
        for (int index = 0; index < 3; index++)
        {
            bezierPoints[i++] = new PointF(coordinates[coordinateIndex], coordinates[coordinateIndex + 1]);
        }
                
    return bezierPoints;
}

TiffImage(TiffFrame frame)

public TiffImage(TiffFrame frame)

初始化一个新的 TiffImage 类对象,指定 frame 参数。此构造函数便于创建 TiffImage 实例,允许开发者指定要加载或处理的帧,从而简化其应用程序中的 Tiff 图像处理任务。

Parameters:

参数类型描述
frameTiffFrame用于初始化图像的 tiff 帧。

TiffImage(TiffFrame[] frames)

public TiffImage(TiffFrame[] frames)

创建一个新的 TiffImage 类实例,提供帧列表作为参数。此构造函数使得能够使用多个帧初始化 TiffImage 对象,便于在软件应用中高效处理和处理 TIFF 图像序列。

Parameters:

参数类型描述
framesTiffFrame[]帧。

getFileFormat()

public long getFileFormat()

检索与图像关联的文件格式值。此属性是图像元数据检索的关键方面,允许软件应用高效识别和解释图像数据的格式。

Returns: long - 文件格式的值

getPremultiplyComponents()

public boolean getPremultiplyComponents()

指示组件是否需要预乘,以确保对视觉元素的高效处理。通过切换此属性来增强渲染过程,简化图形工作流以实现优化性能。

Returns: boolean - 如果组件必须预乘则为 true;否则为 false

setPremultiplyComponents(boolean value)

public void setPremultiplyComponents(boolean value)

指示组件是否需要预乘,以确保对视觉元素的高效处理。通过切换此属性来增强渲染过程,简化图形工作流以实现优化性能。

Parameters:

参数类型描述
valuebooleantrue 表示组件必须预乘;否则为 false

Example: 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 {
    // 保存整幅图像的像素。
    image.savePixels(image.getBounds(), colors);

    // 像素以非预乘形式存储在原始图像中。
    // 需要显式指定相应的选项以获取预乘颜色分量。
    // 预乘颜色分量通过以下公式计算:
    // 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();
}

//输出将如下所示:
//原始颜色:Color [A=127, R=255, G=0, B=0]
//预乘颜色:Color [A=127, R=127, G=0, B=0]
//原始颜色:Color [A=127, R=0, G=255, B=0]
//预乘颜色:Color [A=127, R=0, G=127, B=0]
//原始颜色:Color [A=127, R=0, G=0, B=255]
//预乘颜色:Color [A=127, R=0, G=0, B=127]
//原始颜色:Color [A=127, R=255, G=255, B=0]
//预乘颜色:Color [A=127, R=127, G=127, B=0]
//原始颜色:Color [A=127, R=255, G=0, B=255]
//预乘颜色:Color [A=127, R=127, G=0, B=127]
//原始颜色:Color [A=127, R=0, G=255, B=255]
//预乘颜色:Color [A=127, R=0, G=127, B=127]

getByteOrder()

public final int getByteOrder()

无缝切换 TIFF 文件的字节顺序,确保对数据解释的精确控制。为您的应用程序提供灵活性,以适应多样的文件规范,提升兼容性和数据处理效率。

Returns: int - tiff 字节顺序。

setByteOrder(int value)

public final void setByteOrder(int value)

无缝切换 TIFF 文件的字节顺序,确保对数据解释的精确控制。为您的应用程序提供灵活性,以适应多样的文件规范,提升兼容性和数据处理效率。

Parameters:

参数类型描述
valueinttiff 字节顺序。

getHorizontalResolution()

public double getHorizontalResolution()

检索指定 Image 的水平分辨率(每英寸像素),以便实现精确的调整和渲染功能。轻松访问关键图像元数据,提升图像处理工作流的流畅性,增强用户体验。

Returns: double - 水平分辨率。

注意,默认情况下此值始终为 96,因为不同平台无法返回屏幕分辨率。您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。

Example: 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;

    // 获取 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) {
        // 使用 SetResolution 方法在一次调用中更新两个分辨率值。
        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();
}

// 输出可能如下所示:
// 水平分辨率(每英寸像素数):96.0
// 垂直分辨率(每英寸像素数):96.0

setHorizontalResolution(double value)

public void setHorizontalResolution(double value)

修改指定 Image 的水平分辨率(每英寸像素),以实现精确的调整和渲染功能。轻松访问关键图像元数据,提升图像处理工作流的流畅性,增强用户体验。

Parameters:

参数类型描述
valuedouble

注意,默认情况下此值始终为 96,因为不同平台无法返回屏幕分辨率。您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。 |

getVerticalResolution()

public double getVerticalResolution()

获取指定 Image 的垂直分辨率(每英寸像素),实现精确的调整和渲染优化。轻松利用关键图像数据,简化图像处理工作流,确保应用程序的卓越质量和性能。

Returns: double - 垂直分辨率。

注意,默认情况下此值始终为 96,因为不同平台无法返回屏幕分辨率。您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。

Example: 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;

    // 获取 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) {
        // 使用 SetResolution 方法在一次调用中更新两个分辨率值。
        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();
}

// 输出可能如下所示:
// 水平分辨率(每英寸像素数):96.0
// 垂直分辨率(每英寸像素数):96.0

setVerticalResolution(double value)

public void setVerticalResolution(double value)

获取指定 Image 的垂直分辨率(每英寸像素),实现精确的调整和渲染优化。轻松利用关键图像数据,简化图像处理工作流,确保应用程序的卓越质量和性能。

Parameters:

参数类型描述
valuedouble

注意,默认情况下此值始终为 96,因为不同平台无法返回屏幕分辨率。您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。 |

getActiveFrame()

public final TiffFrame getActiveFrame()

无缝管理活动帧,便于在指定上下文中进行动态导航和操作。让您的应用程序高效地与多媒体内容交互,提升用户参与度和生产力。

Returns: TiffFrame - Active frame.

Example: 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 {
    // 这是用于在各帧上绘制文本的 Font 和 Brush。
    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());

    // 创建 5 帧
    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])));

        // 创建 PNG 图像并在其上绘制页码。
        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);

        // 基于 PNG 图像创建帧。
        com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);

        // 将帧添加到 TIFF 图像中。
        tiffImage.addFrame(frame);
    }

    // 该图像使用单个默认帧创建。让我们将其移除。
    com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
    tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
    tiffImage.removeFrame(0);

    // 如果不将帧添加到其他 TiffImage,请别忘记释放该帧。
    activeFrame.dispose();

    tiffImage.save();
} finally {
    tiffImage.dispose();
}

setActiveFrame(TiffFrame value)

public final void setActiveFrame(TiffFrame value)

无缝管理活动帧,便于在指定上下文中进行动态导航和操作。让您的应用程序高效地与多媒体内容交互,提升用户参与度和生产力。

Parameters:

参数类型描述
valueTiffFrame活动帧。

Example: 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 {
    // 这是用于在各帧上绘制文本的 Font 和 Brush。
    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());

    // 创建 5 帧
    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])));

        // 创建 PNG 图像并在其上绘制页码。
        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);

        // 基于 PNG 图像创建帧。
        com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);

        // 将帧添加到 TIFF 图像中。
        tiffImage.addFrame(frame);
    }

    // 该图像使用单个默认帧创建。让我们将其移除。
    com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
    tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
    tiffImage.removeFrame(0);

    // 如果不将帧添加到其他 TiffImage,请别忘记释放该帧。
    activeFrame.dispose();

    tiffImage.save();
} finally {
    tiffImage.dispose();
}

getFrames()

public final TiffFrame[] getFrames()

检索 TiffFrame 实例数组,以实现对 TIFF 图像中各帧的全面访问和操作。利用该数组的力量简化图像处理工作流,确保对视觉内容的精确控制和优化。

Returns: com.aspose.imaging.fileformats.tiff.TiffFrame[] - TiffFrame 数组。

Example: 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 {
    // 这是用于在各帧上绘制文本的 Font 和 Brush。
    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());

    // 创建 5 帧
    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])));

        // 创建 PNG 图像并在其上绘制页码。
        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);

        // 基于 PNG 图像创建帧。
        com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);

        // 将帧添加到 TIFF 图像中。
        tiffImage.addFrame(frame);
    }

    // 该图像使用单个默认帧创建。让我们将其移除。
    com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
    tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
    tiffImage.removeFrame(0);

    // 如果不将帧添加到其他 TiffImage,请别忘记释放该帧。
    activeFrame.dispose();

    tiffImage.save();
} finally {
    tiffImage.dispose();
}

getPageCount()

public int getPageCount()

检索指定文档的总页数,以便高效导航和管理多页内容。加入此功能可提升用户体验,实现对完整文档结构的无缝访问。

Returns: int - 页数。

getPages()

public Image[] getPages()

无缝访问文档的页面,便于在内容结构中进行动态导航和操作。为您的应用程序提供高效的单页访问,简化文档处理并提升用户交互体验。

Returns: com.aspose.imaging.Image[] - 页面。

hasAlpha()

public boolean hasAlpha()

确定图像是否具有 alpha 通道,为渲染和合成操作提供关键信息。集成此功能以优化视觉处理工作流,确保透明元素的准确呈现和操作。

Returns: boolean - 若存在 alpha 通道则为 true

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;

    // 如果活动 TIFF 帧具有 alpha 通道,则整个 TIFF 图像被视为具有 alpha 通道。
    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();
}

// 输出可能如下所示:
// 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

removeMetadata()

public void removeMetadata()

通过将此 IHasXmpData.XmpData(IHasXmpData.getXmpData/IHasXmpData.setXmpData(XmpPacketWrapper)) 的值设为 null,移除此图像实例的元数据。

getOriginalOptions()

public ImageOptionsBase getOriginalOptions()

检索源文件设置派生的选项,以实现对关键参数(如位深度)及原始图像其他重要属性的无缝保留。使用此方法保持图像处理任务的保真度和一致性,确保在不进行不必要修改的情况下获得最佳结果。例如,如果我们加载一幅每像素 1 位的黑白 PNG 图像,然后使用 DataStreamSupporter.save(String) 方法保存,它将生成每像素 8 位的 PNG 输出图像。为避免此情况并以每像素 1 位保存 PNG 图像,请使用此方法获取相应的保存选项,并将其作为第二个参数传递给 Image.save(String, ImageOptionsBase) 方法。

Returns: ImageOptionsBase - The options based on the original file settings.

addPage(RasterImage page)

public void addPage(RasterImage page)

将新页面无缝合并到现有图像中,扩展其内容和多功能性。利用此方法提升文档的构成和管理,使应用程序能够高效处理多页图像。

Parameters:

参数类型描述
pageRasterImage要添加的页面。

alignResolutions()

public final void alignResolutions()

实现 AlignResolutions 辅助方法以同步水平和垂直分辨率,确保图像尺寸的一致性。此功能通过统一分辨率参数,优化视觉质量和跨平台设备的一致性,从而简化图像处理工作流。

setResolution(double dpiX, double dpiY)

public void setResolution(double dpiX, double dpiY)

为指定的 RasterImage 设置分辨率,以实现对图像渲染和显示属性的精确控制。集成此功能可优化视觉输出,并确保与多种输出设备和平台的兼容性,提升整体用户体验。

Parameters:

参数类型描述
dpiXdouble以每英寸点数表示的 RasterImage 的水平分辨率。
dpiYdouble以每英寸点数表示的 RasterImage 的垂直分辨率。

Example: 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;

    // 获取 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) {
        // 使用 SetResolution 方法在一次调用中更新两个分辨率值。
        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();
}

// 输出可能如下所示:
// 水平分辨率(每英寸像素数):96.0
// 垂直分辨率(每英寸像素数):96.0

normalizeAngle(boolean resizeProportionally, Color backgroundColor)

public void normalizeAngle(boolean resizeProportionally, Color backgroundColor)

使用专为扫描文本文件设计的 NormalizeAngle 方法校正倾斜的扫描图像,确保准确对齐。将此功能无缝集成到文本处理工作流中,以提升文档可读性和质量,提高文本识别和分析任务的整体效率。该方法使用 RasterImage.getSkewAngleRasterImage.rotate(float, boolean, Color) 方法。

Parameters:

参数类型描述
resizeProportionallyboolean如果设置为 true,图像尺寸将根据旋转矩形(角点)投影进行更改;否则保持尺寸不变,仅旋转内部图像内容。
backgroundColorColor背景的颜色。

addFrame(TiffFrame frame)

public final void addFrame(TiffFrame frame)

将指定帧无缝合并到图像中,扩展其内容和多功能性。利用此方法提升图像的构成和管理,使应用程序能够高效处理多帧图像。

Parameters:

参数类型描述
frameTiffFrame要添加的帧。

Example: 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 {
    // 这是用于在各帧上绘制文本的 Font 和 Brush。
    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());

    // 创建 5 帧
    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])));

        // 创建 PNG 图像并在其上绘制页码。
        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);

        // 基于 PNG 图像创建帧。
        com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);

        // 将帧添加到 TIFF 图像中。
        tiffImage.addFrame(frame);
    }

    // 该图像使用单个默认帧创建。让我们将其移除。
    com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
    tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
    tiffImage.removeFrame(0);

    // 如果不将帧添加到其他 TiffImage,请别忘记释放该帧。
    activeFrame.dispose();

    tiffImage.save();
} finally {
    tiffImage.dispose();
}

add(TiffImage image)

public final void add(TiffImage image)

将指定图像中的帧无缝添加到当前帧中,整合其内容并提升构图灵活性。集成此方法以简化应用程序中的帧管理和操作,促进对多帧图像的高效处理。

Parameters:

参数类型描述
imageTiffImage源图像。

addFrames(TiffFrame[] frames)

public final void addFrames(TiffFrame[] frames)

将帧数组无缝集成到图像中,丰富其内容和多功能性。利用此方法提升图像的构成和管理,使应用程序能够高效处理多帧图像。

Parameters:

参数类型描述
framesTiffFrame[]要添加的帧数组

insertFrame(int index, TiffFrame frame)

public final void insertFrame(int index, TiffFrame frame)

在帧序列的指定索引处插入新帧,确保对帧排列的精确控制。使用此方法有效管理帧序列,促进在应用程序中对图像内容的动态操作和组织。

Parameters:

参数类型描述
indexintframe 的索引。
frameTiffFrame待插入的帧。

replaceFrame(int index, TiffFrame newFrame)

public final TiffFrame replaceFrame(int index, TiffFrame newFrame)

将指定位置的帧无缝替换为另一帧,促进图像序列中帧的动态管理。集成此方法以提升帧操作的灵活性和精确性,确保在应用程序中对图像内容的最佳组织和呈现。

Parameters:

参数类型描述
indexint基于零的帧位置。
newFrameTiffFrame

注意:如果不将帧添加到其他 TiffImage,请务必释放/关闭该帧。 |

Returns: TiffFrame - The removed frame.

removeFrame(int index)

public final TiffFrame removeFrame(int index)

轻松根据索引删除图像序列中的帧,简化应用程序中的帧管理。集成此功能可提升帧操作的效率和精确性,促进图像内容的无缝组织和呈现。

Parameters:

参数类型描述
indexint

注意:如果不将帧添加到其他 TiffImage,请务必释放该帧。 |

Returns: TiffFrame - The removed frame.

Example: 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 {
    // 这是用于在各帧上绘制文本的 Font 和 Brush。
    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());

    // 创建 5 帧
    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])));

        // 创建 PNG 图像并在其上绘制页码。
        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);

        // 基于 PNG 图像创建帧。
        com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);

        // 将帧添加到 TIFF 图像中。
        tiffImage.addFrame(frame);
    }

    // 该图像使用单个默认帧创建。让我们将其移除。
    com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
    tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
    tiffImage.removeFrame(0);

    // 如果不将帧添加到其他 TiffImage,请别忘记释放该帧。
    activeFrame.dispose();

    tiffImage.save();
} finally {
    tiffImage.dispose();
}

removeFrame(TiffFrame frame)

public final void removeFrame(TiffFrame frame)

高效删除图像序列中的指定帧,促进应用程序中帧管理的简化。集成此功能可提升帧操作的精确性和灵活性,确保图像内容的无缝组织和呈现。

Parameters:

参数类型描述
frameTiffFrame

注意:如果不将帧添加到其他 TiffImage,请务必释放该帧。 |

resizeProportional(int newWidth, int newHeight, int resizeType)

public final void resizeProportional(int newWidth, int newHeight, int resizeType)

对图像执行等比例缩放操作,在调整尺寸的同时保持其宽高比。使用此方法在应用程序中动态缩放图像,确保内容完整性的视觉表现一致。等比例缩放将根据 newWidth/width 和 newHeight/height 的比例对每个帧进行调整。

Parameters:

参数类型描述
newWidthint新的宽度。
newHeightint新的高度。
resizeTypeint调整大小类型。

resizeWidthProportionally(int newWidth, int resizeType)

public void resizeWidthProportionally(int newWidth, int resizeType)

在保持图像宽高比的同时调整宽度,确保比例缩放以获得最佳视觉呈现。利用此方法在应用程序中动态缩放图像,实现跨各种显示环境的一致且美观的渲染。

Parameters:

参数类型描述
newWidthint新的宽度。
resizeTypeint调整的类型。

Example: This example loads a TIFF image and resizes it proportionally using various resizing methods. 此示例加载 TIFF 图像并使用多种缩放方法按比例调整大小。仅指定宽度,高度会自动计算。

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 {
    // 使用最近邻重采样将尺寸放大 2 倍。
    image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // 使用默认选项保存为 PNG。
    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 {
    // 使用最近邻重采样将尺寸缩小 2 倍。
    image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // 使用默认选项保存为 PNG。
    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 {
    // 使用双线性重采样将尺寸放大 2 倍。
    image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.BilinearResample);

    // 使用默认选项保存为 PNG。
    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 {
    // 使用双线性重采样将尺寸缩小 2 倍。
    image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.BilinearResample);

    // 使用默认选项保存为 PNG。
    image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

resizeHeightProportionally(int newHeight, int resizeType)

public void resizeHeightProportionally(int newHeight, int resizeType)

对图像高度进行比例调整,保持宽高比以确保视觉一致性。使用此方法在应用程序中动态调整图像大小,确保在各种平台和设备上实现最佳显示而不影响内容质量。

Parameters:

参数类型描述
newHeightint新的高度。
resizeTypeint调整的类型。

Example: This example loads a TIFF image and resizes it proportionally using various resizing methods. 此示例加载 TIFF 图像并使用多种缩放方法按比例调整大小。仅指定高度,宽度会自动计算。

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 {
    // 使用最近邻重采样将尺寸放大 2 倍。
    image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // 使用默认选项保存为 PNG。
    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 {
    // 使用最近邻重采样将尺寸缩小 2 倍。
    image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // 使用默认选项保存为 PNG。
    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 {
    // 使用双线性重采样将尺寸放大 2 倍。
    image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);

    // 使用默认选项保存为 PNG。
    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 {
    // 使用双线性重采样将尺寸缩小 2 倍。
    image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);

    // 使用默认选项保存为 PNG。
    image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

rotateFlip(int rotateFlipType)

public void rotateFlip(int rotateFlipType)

对活动帧执行旋转、翻转或两者的组合操作。此方法允许对图像序列中的单帧进行精确操作,提升在应用程序中的图像编辑和合成灵活性。

Parameters:

参数类型描述
rotateFlipTypeint旋转和翻转类型。

Example: 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\\";

// 这是一个帮助类。
class Utils {
    // 获取旋转翻转类型的字符串表示。
    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");
        }
    }
}

// 以下是主要示例
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) {
    // 旋转、翻转并保存到输出文件。
    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();
    }
}

dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)

public void dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)

对当前图像执行抖动处理,以提升视觉质量并减少颜色带状伪影。将此方法集成到图像处理工作流中,以确保颜色过渡更平滑,从而改善整体图像外观和清晰度。

Parameters:

参数类型描述
ditheringMethodint抖动方法。
bitsCountint抖动的最终位计数。
customPaletteIColorPalette抖动的自定义调色板。

Example: 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;

    // 使用包含 16 种颜色的 4 位色彩调色板执行阈值抖动。
    // 指定的位数越多,输出图像的质量越高且尺寸越大。
    // 请注意,目前仅支持 1 位、4 位和 8 位调色板。
    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;

    // 使用仅包含 2 种颜色(黑色和白色)的 1 位色彩调色板执行 Floyd 抖动。
    // 指定的位数越多,输出图像的质量越高且尺寸越大。
    // 请注意,目前仅支持 1 位、4 位和 8 位调色板。
    tiffImage.dither(com.aspose.imaging.DitheringMethod.FloydSteinbergDithering, 1, null);

    tiffImage.save(dir + "sample.FloydSteinbergDithering1.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

crop(Rectangle rectangle)

public void crop(Rectangle rectangle)

使用指定的矩形区域裁剪图像,精确选择所需内容。将此方法集成到图像处理工作流中,以高效去除不需要的区域并聚焦关键细节,提升图像的整体清晰度和构图。

Parameters:

参数类型描述
rectangleRectangle矩形。

Example: The following example crops a TIFF image. 以下示例裁剪 TIFF 图像。裁剪区域通过 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;

    // 裁剪图像。裁剪区域是图像的中心矩形区域。
    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);

    // 将裁剪后的图像保存为 PNG
    tiffImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

crop(int leftShift, int rightShift, int topShift, int bottomShift)

public void crop(int leftShift, int rightShift, int topShift, int bottomShift)

通过指定左、右、上、下方向的偏移量对图像进行裁剪。此方法能够精确选择图像的所需部分,便于高效去除不需要的区域并聚焦关键内容。将此功能集成到图像处理管道中,以在应用程序中根据需要提升清晰度和构图。

Parameters:

参数类型描述
leftShiftint左位移。
rightShiftint右位移。
topShiftint上位移。
bottomShiftint下位移。

Example: The following example crops a TIFF image. 以下示例裁剪 TIFF 图像。裁剪区域通过左、上、右、下边距指定。

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;

    // 再次裁剪。设置图像尺寸的 10% 边距。
    int horizontalMargin = tiffImage.getWidth() / 10;
    int verticalMargin = tiffImage.getHeight() / 10;
    tiffImage.crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);

    // 将裁剪后的图像保存为 PNG。
    tiffImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

binarizeFixed(byte threshold)

public void binarizeFixed(byte threshold)

使用预定义阈值对图像进行二值化,将其转换为前景和背景区域明确的二值图像。将此方法集成到图像处理工作流中,以促进分割和特征提取任务,提升应用程序中图像分析的准确性和效率。

Parameters:

参数类型描述
thresholdbyte阈值。若像素的对应灰度值大于阈值,则赋值为 255,否则为 0。

Example: The following example binarizes a TIFF image with the predefined threshold. 以下示例使用预定义阈值对 TIFF 图像进行二值化。二值化图像仅包含两种颜色——黑色和白色。

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;

    // 使用阈值 127 对图像进行二值化。
    // 如果像素的对应灰度值大于 127,则赋值为 255;否则为 0。
    tiffImage.binarizeFixed((byte) 127);
    tiffImage.save(dir + "sample.BinarizeFixed.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

binarizeOtsu()

public void binarizeOtsu()

利用 Otsu 阈值法对图像进行二值化,自动根据图像直方图确定最佳阈值。将此方法集成到图像处理工作流中,以实现有效的分割和特征提取,提升应用程序中图像分析任务的准确性和可靠性。

Example: The following example binarizes a TIFF image with Otsu thresholding. 以下示例使用 Otsu 阈值法对 TIFF 图像进行二值化。二值化图像仅包含两种颜色——黑色和白色。

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;

    // 使用 Otsu 阈值法对图像进行二值化。
    tiffImage.binarizeOtsu();
    tiffImage.save(dir + "sample.BinarizeOtsu.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

binarizeBradley(double brightnessDifference, int windowSize)

public void binarizeBradley(double brightnessDifference, int windowSize)

在图像上实现二值化,采用 Bradley 自适应阈值算法结合积分图阈值。此方法根据图像邻域动态计算局部阈值,增强对不同光照条件的适应性,并确保后续处理任务的稳健分割。

Parameters:

参数类型描述
brightnessDifferencedouble像素与以该像素为中心的 s × s 窗口像素平均值之间的亮度差。
windowSizeint以该像素为中心的 s × s 窗口像素的大小

Example: The following example binarizes a TIFF image with Bradley’s adaptive thresholding algorithm with the specified window size. 以下示例使用 Bradley 自适应阈值算法并指定窗口大小对 TIFF 图像进行二值化。二值化图像仅包含两种颜色——黑色和白色。

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;

    // 使用亮度差 5 对图像进行二值化。亮度是指像素与以该像素为中心的 10×10 窗口像素平均值之间的差异。
    tiffImage.binarizeBradley(5, 10);
    tiffImage.save(dir + "sample.BinarizeBradley5_10x10.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

grayscale()

public void grayscale()

将图像转换为灰度表示,转化为单通道图像,每个像素表示强度。将此方法集成到图像处理管道中,以简化分析并提升与基于灰度算法的兼容性,促进在应用程序中进行各种计算机视觉和图像分析任务。

Example: The following example transforms a colored TIFF image to its grayscale representation. 以下示例将彩色 TIFF 图像转换为灰度表示。灰度图像仅由灰色阴影组成,仅携带强度信息。

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();
}

adjustGamma(float gamma)

public void adjustGamma(float gamma)

对图像应用伽马校正,调整像素强度以实现所需的色彩平衡。将此方法集成到图像处理工作流中,以提升视觉质量并改善后续分析或显示任务的准确性。

Parameters:

参数类型描述
伽马float红色、绿色和蓝色通道的伽马系数

Example: The 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;

    // 为红色、绿色和蓝色通道设置伽马系数。
    tiffImage.adjustGamma(2.5f);
    tiffImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

public void adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

使用红、绿、蓝通道的单独系数对图像进行伽马校正,允许对色彩平衡和对比度进行精细调节。将此方法集成到图像处理管道中,以实现对色彩渲染的精确控制并提升应用程序中的视觉保真度。

Parameters:

参数类型描述
gammaRedfloat红色通道的伽马系数
gammaGreenfloat绿色通道的伽马系数
gammaBluefloat蓝色通道的伽马系数

Example: The 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;

    // 为红色、绿色和蓝色通道设置各自的伽马系数。
    tiffImage.adjustGamma(1.5f, 2.5f, 3.5f);
    tiffImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustBrightness(int brightness)

public void adjustBrightness(int brightness)

实现对图像的 brightness 调整,允许修改整体亮度水平。将此方法集成到图像处理工作流中,以提升可见性并改善应用程序中图像的视觉质量。

Parameters:

参数类型描述
brightnessint亮度值。

Example: 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;

    // 设置亮度值。亮度的可接受范围为 [-255, 255]。
    tiffImage.adjustBrightness(50);
    tiffImage.save(dir + "sample.AdjustBrightness.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustContrast(float contrast)

public void adjustContrast(float contrast)

增强 Image 实例的对比度,放大其明暗区域之间的差异。集成此功能以提升图像的视觉清晰度和整体质量。

Parameters:

参数类型描述
contrastfloat对比度值(范围为 [-100; 100])

Example: 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;

    // 设置对比度值。对比度的可接受范围为 [-100f, 100f]。
    tiffImage.adjustContrast(50f);
    tiffImage.save(dir + "sample.AdjustContrast.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

filter(Rectangle rectangle, FilterOptionsBase options)

public void filter(Rectangle rectangle, FilterOptionsBase options)

在指定的矩形区域内过滤内容,应用指定的图像处理滤镜以增强或修改所选区域。将此方法集成到图像操作工作流中,以在应用程序中实现针对性的增强或转换。

Parameters:

参数类型描述
rectangleRectangle矩形。
optionsFilterOptionsBase选项。

Example: 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;

    // 对整幅图像应用矩形大小为 5 的中值滤波器。
    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;

    // 对整幅图像应用核大小为 5 的双边平滑滤波器。
    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;

    // 对整幅图像应用半径为 5、sigma 值为 4.0 的高斯模糊滤波器。
    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;

    // 对整幅图像应用半径为 5、平滑值为 4.0 的 Gauss-Wiener 滤波器。
    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;

    // 对整幅图像应用长度为 5、平滑值为 4.0、角度为 90.0 度的运动 Wiener 滤波器。
    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;

    // 对整幅图像应用核大小为 5、sigma 值为 4.0 的锐化滤波器。
    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();
}

resize(int newWidth, int newHeight, ImageResizeSettings settings)

public void resize(int newWidth, int newHeight, ImageResizeSettings settings)

根据指定设置调整图像大小,以实现对尺寸、宽高比和缩放行为的精确控制。将此方法集成到您的图像处理工作流中,以实现针对应用程序特定需求的自定义调整大小操作。

Parameters:

参数类型描述
newWidthint新的宽度。
newHeightint新的高度。
settingsImageResizeSettings调整大小的设置。

Example: 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();

// 基于加权和混合有理函数以及 lanczos3 插值的自适应算法。
resizeSettings.setMode(com.aspose.imaging.ResizeType.AdaptiveResample);

// 小矩形滤波器
resizeSettings.setFilterType(com.aspose.imaging.ImageFilterType.SmallRectangular);

// 调色板中的颜色数量。
resizeSettings.setEntriesCount(256);

// 未使用颜色量化
resizeSettings.setColorQuantizationMethod(com.aspose.imaging.ColorQuantizationMethod.None);

// 欧几里得方法
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;

    // 使用自适应重采样将尺寸缩小 2 倍。
    tiffImage.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings);

    // 保存为 PNG
    tiffImage.save(dir + "downsample.adaptive.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}