EPS to PNG
Convert EPS to PNG via API Solution for C++.
Aspose.Page for EPS to PNG converter offers conversion of Encapsulated PostScript (EPS) file to PNG image with using of any language supported by C++.
The API you see here can be used to create your own cross-platform application or be integrated into your C++ project.
In order to convert XPS to PNG:
Aspose.Page for C++ API which is a feature-rich, powerful and easy to use document manipulation and conversion API for C++ platform.
You can download its latest version directly, just open NuGet package manager, and search for Aspose.Page.Cpp and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.Page.Cpp
Steps to Convert EPS to PNG using C++
Aspose.Page makes it easy for the developers to load and convert EPS files to PNG in just a few lines of code.
- Load EPS file with Aspose.Page for C++.
- Create the object of ImageSaveOptions Class and set image format as ImageFormat::Png .
- Get bytes array of image calling SaveAsImage with defined options.
- Save image by writing image bytes to output stream.
EPS to PNG C++ Conversion
// 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.eps"); | |
// 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::Png); | |
// 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()); | |
} | |
} | |
EPS to PNG Conversion Web Application
EPS What is EPS File Format
EPS (EPSF) or Encapsulated PostScript File Format is the format that is actually a PS program that describes what would a single page look like. It is actually limited PS plus particular notes that help encapsulate PostScript graphics to another document. EPS perfectly supports vector graphics or combined vector-raster graphics. The peculiarity of the format is that as soon as it is imported into a document, it cannot be edited anymore. That is one of the reasons to convert this format to the one you are able to work with.
PNG What is PNG File Format
Portable Network Graphics or PNG is one of the most popular image formats. It gives you really good compression maintaining the high level of quality of the picture. PNG is also one of the best formats for web projects, as the files are lighter and images are easy to scale. One drawback of the format when used on the web is that it is not possible to add keywords to the image directly.