将 EPUB 转换为 BMP – C# 示例

BMP 是微软开发的一种位图格式,几乎可用于存储任何类型的位图数据。BMP 文件格式支持各种色深、alpha 通道、颜色配置文件和可选的数据压缩,因此用途相对广泛。使用 Aspose.HTML for .NET,您可以通过编程将 EPUB 转换为 BMP 格式,并完全控制各种转换参数。

本文将介绍如何使用 Converter 类的 ConvertEPUB() 方法将 EPUB 转换为 BMP,以及如何应用 ImageSaveOptionsICreateStreamProvider 参数。

在线 EPUB 转换器

您可以使用 Aspose.HTML for .NET API 实时将 EPUB 转换为其他格式。首先,从本地驱动器加载 EPUB 文件,然后运行示例。示例中的保存选项为默认设置。您将立即以单独文件的形式收到转换结果。

                
            

如果你想通过编程将 EPUB 转换为 BMP,请参阅以下 C# 代码示例。

用 C# 将 EPUB 转换为 BMP

使用 Converter.ConvertEPUB()方法是将EPUB文件转换成各种格式的最常见方法。你应该遵循以下几个步骤:

  1. 打开现有 EPUB 文件。在示例中,我们使用 System.IO.FileStream 类的 OpenRead() 方法从指定路径的文件系统中打开并读取 EPUB 文件。
  2. 创建一个新的 ImageSaveOptions 对象,其属性为 ImageFormat.Bmp。默认情况下,格式属性为 PNG
  3. 使用转换器类的 ConvertEPUB()方法将 EPUB 保存为 BMP 图像。您需要向 ConvertEPUB() 方法传递 EPUB 文件流、ImageSaveOptions 和输出文件路径,以实现 EPUB 到 BMP 的转换。

请看下面的 C# 代码片段,它显示了使用 Aspose.HTML for .NET 将 EPUB 转换为 BMP 的过程。

 1// Convert EPUB to BMP 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.bmp");
 8
 9// Create an instance of the ImageSaveOptions class 
10ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Bmp);
11
12// Call the ConvertEPUB() method to convert EPUB to BMP
13Converter.ConvertEPUB(stream, options, savePath);

ImageSaveOptions

Aspose.HTML 允许使用默认或自定义保存选项将 EPUB 转换为 BMP。使用 ImageSaveOptions 可以调整渲染过程。您可以指定 page sizemarginsCSS media-type等。

PropertyDescription
CompressionSets Tagged Image File Format (TIFF) Compression. By default, this property is LZW.
CSSGets a CssOptions object which is used for configuration of CSS properties processing.
FormatSets the ImageFormat (JPG, PNG, BMP, TIFF, or GIF). By default, this property is PNG.
BackgroundColorThis property sets the color that will fill the background. By default, this property is Transparent.
PageSetupThis property gets a page setup object and uses it for configuration output page-set.
HorizontalResolutionSets horizontal resolution for output images in pixels per inch. The default value is 300 dpi.
VerticalResolutionSets vertical resolution for output images in pixels per inch. The default value is 300 dpi.
UseAntialiasingThis property sets the image rendering quality. Antialiasing is enabled by default.
TextGets a TextOptions object which is used for configuration of text rendering.

要了解有关 ImageSaveOptions 类的更多信息,请阅读 微调转换器 部分。

使用图像保存选项将 EPUB 转换为 BMP

将 EPUB 转换为 BMP 并指定 ImageSaveOptions,需要遵循以下几个步骤:

  1. 打开现有 EPUB 文件
  2. 创建一个新的 ImageSaveOptions 对象并指定保存选项。
  3. 使用转换器类的 ConvertEPUB() 方法将 EPUB 保存为 BMP 图像。您需要向 ConvertEPUB() 方法传递 EPUB 文件流、ImageSaveOptions 和输出文件路径,以便将 EPUB 转换为 BMP。

下面的 C# 代码片段显示了如何使用自定义保存选项将 EPUB 转换为 BMP:

 1// Convert EPUB to BMP 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 for converted file saving 
 7string savePath = Path.Combine(OutputDir, "input-options.bmp");
 8
 9// Initialize ImageSaveOptions 
10ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Bmp)
11{
12    UseAntialiasing = true,
13    HorizontalResolution = 400,
14    VerticalResolution = 400,
15    BackgroundColor = System.Drawing.Color.AliceBlue
16};
17
18// Call the ConvertEPUB() method to convert EPUB to BMP
19Converter.ConvertEPUB(stream, options, savePath);

ImageSaveOptions() 构造函数初始化 ImageSaveOptions 类的实例,并将其传递给 ConvertEPUB() 方法。ConvertEPUB() 方法接收 streamoptions、输出文件路径 savePath 并执行转换操作。

在示例中,我们使用

您可以从 GitHub 下载完整的示例和数据文件。

Aspose.HTML提供了一个免费的在线 EPUB到BMP转换器,转换EPUB到BMP图像质量高,方便,快捷。只需上传、转换文件并在几秒钟内获得结果!

文本 “EPUB 到 BMP 转换器”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.