PS 转 GIF
通过 C++ 的 API 解决方案将 PS 转换为 GIF。
Aspose.Page for PS 到 GIF 转换器提供使用 C++ 支持的任何语言将 PostScript (PS) 文件转换为 GIF 图像的功能。
您在此处看到的 API 可用于创建您自己的跨平台应用程序或集成到您的 C++ 项目中。
要将 XPS 转换为 GIF:
Aspose.Page for C++ API 是一个功能丰富、功能强大且易于使用的 C++ 平台文档操作和转换 API。
您可以直接下载其最新版本,只需打开NuGet包管理器,然后搜索Aspose.Page.Cpp并安装。您还可以从包管理器控制台使用以下命令。
Package Manager Console Command
PM> Install-Package Aspose.Page.Cpp
使用 C++ 将 PS 转换为 GIF 的步骤
Aspose.Page 使开发人员只需几行代码即可轻松加载 PS 文件并将其转换为 GIF。
- 使用 Aspose.Page for C++ 加载 PS 文件。
- 创建 ImageSaveOptions Class 对象并将图像格式设置为 ImageFormat::Gif 。
- 使用定义的选项调用 SaveAsImage 获取图像的字节数组。
- 通过将图像字节写入输出流来保存图像。
PS 到 GIF C++ 转换
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion(); | |
// Initialize PsDocument with the name of PostScript file. | |
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps"); | |
// If you want to convert Postscript file despite of minor errors set this flag | |
bool suppressErrors = true; | |
//Initialize options object with necessary parameters. | |
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(); | |
//Set output image format. | |
options->set_ImageFormat(Aspose::Page::Drawing::Imaging::ImageFormat::Giff); | |
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. | |
options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"})); | |
// Save PS document as array of image bytes, one bytes array for one page. | |
System::ArrayPtr<System::ArrayPtr<uint8_t>> imagesBytes = document->SaveAsImage(options); | |
//Save images bytes arrays as image files. | |
int32_t i = 0; | |
for (System::ArrayPtr<uint8_t> imageBytes : imagesBytes) | |
{ | |
System::String imagePath = System::IO::Path::GetFullPath(dataDir + u"out_image" + System::Convert::ToString(i) + u"." + System::ObjectExt::ToString(options->get_ImageFormat()).ToLower()); | |
{ | |
System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(imagePath, System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ fs}); | |
// ------------------------------------------ | |
try | |
{ | |
fs->Write(imageBytes, 0, imageBytes->get_Length()); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
i++; | |
} | |
//Review errors | |
if (suppressErrors) | |
{ | |
for (auto&& ex : System::IterateOver(options->get_Exceptions())) | |
{ | |
System::Console::WriteLine(ex->get_Message()); | |
} | |
} | |
PS 到 GIF 转换网络应用程序
将 PS 转换为 GIF 现在通过访问我们的现场演示网站。
PS 什么是PS文件格式
PS 格式是页面描述语言 (PDL) 格式之一。它能够在页面上包含图形和文本信息。这就是为什么大多数图像编辑程序都支持该格式的原因。 postscript 文件本身就是对打印机的一种指令。它包含有关从其页面打印什么以及如何打印的信息。
GIF 什么是GIF文件格式
全球知名的图形交换格式 GIF 是一种用于轻量级动画的图形格式。它是一种无损压缩的位图图像格式。它非常适合为低质量视频创建颜色数量有限的内容。您可以在任何社交网络、Messenger 或其他通信解决方案上找到 GIF。