将 EPUB 转换为 TIFF
使用 Aspose.HTML for .NET,您可以通过程序将 EPUB 转换为 TIFF 格式,并完全控制各种转换参数。在本文中,您将了解如何使用 Converter 类的 ConvertEPUB() 方法将 EPUB 转换为 TIFF 以及如何应用 ImageSaveOptions 和 ICreateStreamProvider 参数。
在线 EPUB 转换器
您可以检查 Aspose.HTML API 功能并实时转换 EPUB。请从本地文件系统加载 EPUB 文件,选择输出格式并运行示例。在示例中,默认设置了保存选项。您将立即以单独文件的形式收到结果。
如果你想通过编程将 EPUB 转换为 TIFF,请参阅以下 C# 代码示例。
将 EPUB 转换为 TIFF
使用 Converter.ConvertEPUB()方法是将EPUB文件转换成各种格式的最常见方法。要将EPUB转换为TIFF,应遵循以下几个步骤:
- 打开现有 EPUB 文件。在示例中,我们使用 System.IO.FileStream 类的 OpenRead() 方法从指定路径的文件系统中打开并读取 EPUB 文件。
- 创建一个具有 TIFF 图像格式的新 ImageSaveOptions 对象。默认情况下,格式属性为 PNG。
- 使用转换器类的 ConvertEPUB()方法将 EPUB 保存为 TIFF 图像。您需要向 ConvertEPUB() 方法传递 EPUB 文件流、ImageSaveOptions 和输出文件路径,以实现 EPUB 到 TIFF 的转换。
请看下面的 C# 代码片段,它显示了使用 Aspose.HTML for .NET 将 EPUB 转换为 TIFF 的过程。
1// Convert EPUB to TIFF using C#
2
3// Open an existing EPUB file for reading
4using FileStream stream = File.OpenRead(DataDir + "input.epub");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "input-output.tiff");
8
9// Create an instance of the ImageSaveOptions class
10ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Tiff);
11
12// Call the ConvertEPUB() method to convert EPUB to TIFF
13Converter.ConvertEPUB(stream, options, savePath);
保存选项 – ImageSaveOptions
Aspose.HTML 允许使用默认或自定义保存选项将 EPUB 转换为 TIFF。使用 ImageSaveOptions 可以调整渲染过程。您可以指定页面大小、页边距、CSS、压缩等。
Property | Description |
---|---|
Compression | Sets Tagged Image File Format (TIFF) Compression. By default, this property is LZW. |
CSS | Gets a CssOptions object which is used for configuration of CSS properties processing. |
Format | Sets the ImageFormat (JPG, PNG, BMP, TIFF, or GIF). By default, this property is PNG. |
BackgroundColor | This property sets the color that will fill the background. By default, this property is Transparent. |
PageSetup | This property gets a page setup object and uses it for configuration output page-set. |
HorizontalResolution | Sets horizontal resolution for output images in pixels per inch. The default value is 300 dpi. |
VerticalResolution | Sets vertical resolution for output images in pixels per inch. The default value is 300 dpi. |
UseAntialiasing | This property sets the image rendering quality. Antialiasing is enabled by default. |
Text | Gets a TextOptions object which is used for configuration of text rendering. |
要了解有关 ImageSaveOptions 类的更多信息,请阅读 微调转换器 一文。
使用图像保存选项将 EPUB 转换为 TIFF
要将 EPUB 转换为指定图像保存选项的 TIFF 格式,您需要遵循以下几个步骤:
- 打开现有 EPUB 文件
- 创建一个新的 ImageSaveOptions 对象并指定保存选项。
- 使用转换器类的 ConvertEPUB() 方法将 EPUB 保存为 TIFF 图像。您需要向 ConvertEPUB() 方法传递 EPUB 文件流、ImageSaveOptions 和输出文件路径,以便将 EPUB 转换为 TIFF。
下面的 C# 代码片段显示了如何使用自定义保存选项将 EPUB 转换为 TIFF:
1// Convert EPUB to TIFF in C# with custom settings
2
3// Open an existing EPUB file for reading
4using FileStream stream = File.OpenRead(DataDir + "input.epub");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "input-options.tiff");
8
9// Create an instance of the ImageSaveOptions class
10ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Tiff)
11{
12 Compression = Compression.None,
13 UseAntialiasing = true,
14 HorizontalResolution = 400,
15 VerticalResolution = 400,
16 BackgroundColor = System.Drawing.Color.AliceBlue
17};
18options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(800, 500), new Margin(30, 20, 10, 10));
19
20// Call the ConvertEPUB() method to convert EPUB to TIFF
21Converter.ConvertEPUB(stream, options, savePath);
ImageSaveOptions() 构造函数初始化 ImageSaveOptions 类的实例,并将其传递给 ConvertEPUB() 方法。ConvertEPUB() 方法接收 stream
、options
、输出文件路径 savePath
并执行转换操作。
在示例中,我们使用
Compression
属性,用于设置 TIFF 压缩。可用值为 LVZ、CCITT3、CCITT4、Rle 和 None。我们使用 None 压缩模式。默认情况下,该属性为 LZW。BackgroundColor
属性,用于指定背景填充的颜色。默认的 BackgroundColor 是透明色。HorizontalResolution
和VerticalResolution
属性以每英寸像素为单位设置输出图像的水平/垂直分辨率。默认情况下,这些属性为 300 dpi。UseAntialiasing
属性,用于设置该图像的渲染质量。- 页面设置 属性以像素为单位指定 page size 和 margins。
您可以从 GitHub 下载完整的示例和数据文件。
Aspose.HTML提供免费的在线 EPUB到TIFF转换器,可将EPUB转换为高质量的TIFF图像,简单快捷。只需上传、转换文件,几秒钟就能得到结果!