在 Android 上将 PowerPoint 演示文稿转换为 TIFF

概述

TIFF(Tagged Image File Format)是一种广泛使用的无损光栅图像格式,以其卓越的质量和对图形细节的完整保留而著称。设计师、摄影师和桌面出版人员经常选择 TIFF 来保持图像的图层、颜色精度和原始设置。

使用 Aspose.Slides,您可以轻松地将 PowerPoint 幻灯片(PPT、PPTX)和 OpenDocument 幻灯片(ODP)直接转换为高质量的 TIFF 图像,确保演示文稿保留最大的视觉保真度。

将演示文稿转换为 TIFF

使用由 Presentation 类提供的 save 方法,您可以快速将整个 PowerPoint 演示文稿转换为 TIFF。生成的 TIFF 图像对应默认幻灯片尺寸。

以下代码演示了如何将 PowerPoint 演示文稿转换为 TIFF:

// 实例化表示演示文稿文件 (PPT、PPTX、ODP 等) 的 Presentation 类。
Presentation presentation = new Presentation("presentation.pptx");
try {
    // 将演示文稿保存为 TIFF。
    presentation.save("output.tiff", SaveFormat.Tiff);
} finally {
    presentation.dispose();
}

将演示文稿转换为黑白 TIFF

TiffOptions 类中的 setBwConversionMode 方法允许您指定在将彩色幻灯片或图像转换为黑白 TIFF 时使用的算法。请注意,仅当 setCompressionType 方法设置为 CCITT4CCITT3 时,此设置才有效。

假设我们有一个名为 “sample.pptx” 的文件,包含如下幻灯片:

演示文稿幻灯片

以下代码演示了如何将彩色幻灯片转换为黑白 TIFF:

TiffOptions tiffOptions = new TiffOptions();
tiffOptions.setCompressionType(TiffCompressionTypes.CCITT4);
tiffOptions.setBwConversionMode(BlackWhiteConversionMode.Dithering);

Presentation presentation = new Presentation("sample.pptx");
try {
    presentation.save("output.tiff", SaveFormat.Tiff, tiffOptions);
} finally {
    presentation.dispose();
}

结果如下:

黑白 TIFF

将演示文稿转换为自定义尺寸的 TIFF

如果您需要具有特定尺寸的 TIFF 图像,可以使用 TiffOptions 中提供的方法设置所需的值。例如,setImageSize 方法允许您定义生成图像的尺寸。

以下代码演示了如何将 PowerPoint 演示文稿转换为具有自定义尺寸的 TIFF 图像:

// 实例化表示演示文稿文件 (PPT、PPTX、ODP 等) 的 Presentation 类。
Presentation presentation = new Presentation("presentation.pptx");
try {
    TiffOptions tiffOptions = new TiffOptions();

    // 设置压缩类型。
    tiffOptions.setCompressionType(TiffCompressionTypes.Default);
    /*
    压缩类型:
        Default - 指定默认的压缩方案 (LZW)。
        None - 指定无压缩。
        CCITT3
        CCITT4
        LZW
        RLE
    */

    // 深度取决于压缩类型,不能手动设置。

    // 设置图像 DPI。
    tiffOptions.setDpiX(200);
    tiffOptions.setDpiY(200);

    // 设置图像尺寸。
    tiffOptions.setImageSize(new Size(1728, 1078));

    INotesCommentsLayoutingOptions notesOptions = new NotesCommentsLayoutingOptions();
    notesOptions.setNotesPosition(NotesPositions.BottomFull);
    tiffOptions.setSlidesLayoutOptions(notesOptions);

    // 将演示文稿保存为指定尺寸的 TIFF。
    presentation.save("tiff-ImageSize.tiff", SaveFormat.Tiff, tiffOptions);
} finally {
    presentation.dispose();
}   

将演示文稿转换为具有自定义像素格式的 TIFF

使用 TiffOptions 类中的 setPixelFormat 方法,您可以为生成的 TIFF 图像指定首选的像素格式。

以下代码演示了如何将 PowerPoint 演示文稿转换为具有自定义像素格式的 TIFF 图像:

// 实例化表示演示文稿文件 (PPT、PPTX、ODP 等) 的 Presentation 类。
Presentation presentation = new Presentation("presentation.pptx");
try {
    TiffOptions tiffOptions = new TiffOptions();

    tiffOptions.setPixelFormat(ImagePixelFormat.Format8bppIndexed);
    /*
    ImagePixelFormat 包含以下值(如文档所述):
        Format1bppIndexed - 1 位每像素,索引。
        Format4bppIndexed - 4 位每像素,索引。
        Format8bppIndexed - 8 位每像素,索引。
        Format24bppRgb    - 24 位每像素,RGB。
        Format32bppArgb   - 32 位每像素,ARGB。
    */
    
    // 将演示文稿保存为指定图像尺寸的 TIFF。
    presentation.save("Tiff-PixelFormat.tiff", SaveFormat.Tiff, tiffOptions);
} finally {
    presentation.dispose();
}

常见问题

我可以只将单个幻灯片而不是整个 PowerPoint 演示文稿转换为 TIFF 吗?

可以。Aspose.Slides 允许您单独将 PowerPoint 和 OpenDocument 演示文稿中的各个幻灯片转换为 TIFF 图像。

在将演示文稿转换为 TIFF 时,幻灯片数量是否有限制?

没有限制,Aspose.Slides 对幻灯片数量没有任何限制。您可以将任意大小的演示文稿转换为 TIFF 格式。

在将幻灯片转换为 TIFF 时,PowerPoint 动画和转场效果会被保留吗?

不会,TIFF 是静态图像格式。因此,动画和转场效果不会被保留,仅导出幻灯片的静态快照。