通过 C++ 将 CGM 转换为 BMP

CGM 到 BMP C++ 转换。程序员可以使用 API 示例代码,在各种应用程序中使用 VC++、GNU C++ 将 CGM 文件批量转换为 BMP。

在 C++ 中将 CGM 转换为 BMP

如何将 CGM 转换为 BMP?您可以使用现代文档处理 C++ API 轻松地以编程方式将文档从 CGM 转换为 BMP 格式。只需使用几行 C++ 代码即可转换高质量的文件。Aspose.PDF 库将允许任何开发人员高效地解决使用 C++ 将 CGM 转换为 BMP 的任务。

有关代码片段和其他可能的转换格式的更详细描述,请参见 文档 页面。此外,您还可以查看我们的图书馆支持的其他 转换 格式。

为了将 CGM 转换为 BMP,我们将使用 Aspose.PDF for C++ API,它是一个功能丰富、强大且易于使用的 C++ 平台转换 API。在 文档 页面上查看安装库的详细信息。要验证该库的好处,请尝试使用将 CGM 转换为 BMP 的代码片段。打开 NuGet 包管理器,搜索 Aspose.PDF,然后安装。您也可以使用包管理器控制台中的以下命令:

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

如何将 CGM 转换为 BMP


C++ 开发人员只需几行代码即可轻松加载 CGM 个文件并将其转换为 BMP。

  1. 初始化新文档
  2. 使用 “大小和分辨率” 创建并设置 BMPDevice 类的实例
  3. 使用页面索引和输出文件路径作为参数调用 bmpDevice.process 方法
  4. 最后,保存输出 BMP 文件

系统要求


所有主要操作系统都支持 C++ 的 Aspose.PDF。只要确保你有以下先决条件即可。

  • 微软 Windows 或兼容 C++ 运行时环境的操作系统,适用于 Windows 32 位、Windows 64 位和 Linux 64 位。
  • 像微软 Visual Studio 这样的开发环境。
  • 在你的项目中引用的 Aspose.PDF for C++ DLL。

以下示例演示了如何在 C++ 中将 CGM 转换为 BMP。你可以按照以下简单步骤将你的 CGM 文件转换为 BMP 格式。首先,上传你的 CGM 文件,然后将其保存为 BMP 文件。您可以使用完全限定的文件名进行 CGM 读取和 BMP 写入。输出 BMP 的内容和格式将与原始 CGM 文档相同。

示例:通过 C++ 将 CGM 转换为 BMP

此示例代码显示 CGM 到 BMP C++ 的转换

Input file:

File not added

Output format:

BMP

Output file:

void Convert_PDF_To_Images::ConvertPDFusingImageDevice()
{
    std::clog << __func__ << ": Start" << std::endl;

    // String for path name
    String _dataDir("C:\\Samples\\Conversion\\");

    // String for input file name
    String infilename("sample.cgm");
    
    // Open document
    auto document = MakeObject<Document>();

    // Add empty page in empty document
    auto page = document->get_Pages()->Add();
    auto image = MakeObject<Aspose::Pdf::Image>();
    image->set_File(_dataDir + infilename);

    // Add image on a page
    page->get_Paragraphs()->Add(image);

    // Create Resolution object            
    auto resolution = MakeObject<Aspose::Pdf::Devices::Resolution>(300); //300 dpi

    System::SmartPtr<Aspose::Pdf::Devices::ImageDevice>
    bmpDevice = MakeObject<Aspose::Pdf::Devices::BmpDevice>(resolution);
    
    auto document = MakeObject<Document>(_dataDir + u"ConvertAllPagesToBmp.pdf");

    ConvertPDFtoImage(bmpDevice, u"bmp", document);

    std::clog << __func__ << ": Finish" << std::endl;

}

void Convert_PDF_To_Images::ConvertPDFtoImage(
 System::SmartPtr<Aspose::Pdf::Devices::ImageDevice> imageDevice,
 String ext, System::SmartPtr<Document> document)
{
    // String for path name
    String _dataDir("C:\\Samples\\Conversion\\");

    for (int pageCount = 1; pageCount <= document->get_Pages()->get_Count(); pageCount++)
    {
    String outfilename = String::Format(u"{0}PageToBmp{1}_out.{2}",
    _dataDir, pageCount, ext);

    auto imageStream = System::IO::File::OpenWrite(outfilename);

    // Create Resolution object
    auto resolution = MakeObject<Aspose::Pdf::Devices::Resolution>(300);

    // Convert a particular page and save the image to stream
    imageDevice->Process(document->get_Pages()->idx_get(pageCount), imageStream);

    // Close stream
    imageStream->Close();
    }
}

C++ 库将 CGM 转换为 BMP

Aspose.PDF for C++ 是一个强大的处理库,它使开发人员无需使用 Adobe Acrobat 即可创建、读取和操作 PDF 文档。它提供了广泛的功能,例如创建表单、添加/编辑文本、操作 PDF 页面、添加注释、处理自定义字体等等。

Aspose.PDF for C++ 是一个允许开发人员向其应用程序添加 PDF 处理功能的库。API 可用于构建任何类型的 32 位和 64 位应用程序,无需使用 Adobe Acrobat 即可生成或读取、转换和操作 PDF 文件。

你可以在 API 参考的 Aspose.PDF for C++ 库 中找到每个类和方法的详细解释和示例。还建议查看 文档