XPS to BMP

Convert XPS to BMP via API Solution for C++.

 

Aspose.Page for XPS to BMP converter offers conversion to BMP 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 BMP:

  • 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 XPS to BMP using C++

Aspose.Page makes it easy for the developers to load and convert XPS files to BMP in just a few lines of code.

  1. Create instance of XpsDocument Class with input file name and XpsLoadOptions as constructor parameters.
  2. Define save options as instance of BmpSaveOptions .
  3. Call SaveAsImage method of XPS document to save each document page to an array bytes of image.
  4. Process errors if needs.
XPS to BMP C++ Conversion
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
//Outut file
System::String outputFileName = dataDir + u"XPStoImage_out.bmp";
// Load XPS document form the XPS file
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
// Initialize options object with necessary parameters.
System::SharedPtr<BmpSaveOptions> options = System::MakeObject<BmpSaveOptions>();
options->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality);
options->set_Resolution(300);
options->set_PageNumbers(System::MakeArray<int32_t>({1, 2, 6}));
// Save XPS document to the images byte arrays. The first dimension is for inner documents
// and the second one is for pages within inner documents.
System::ArrayPtr<System::ArrayPtr<System::ArrayPtr<uint8_t>>> imagesBytes = document->SaveAsImage(options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int32_t i = 0; i < imagesBytes->get_Length(); i++)
{
// Iterate through partition pages
for (int32_t j = 0; j < imagesBytes[i]->get_Length(); j++)
{
// Initialize image output stream
{
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + System::IO::Path::DirectorySeparatorChar + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream});
// ------------------------------------------
try
{
imageStream->Write(imagesBytes[i][j], 0, imagesBytes[i][j]->get_Length());
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
}
}

XPS to BMP Conversion Web Application

XPS What is XPS File Format

XPS format is similar to PDF format. Both are page description language (PDL) formats. EPS is based on HTML and not on PostScript language. The .eps file is capable to contain a markup of the document's structure along with the information on how the document would look like. There are also added instructions on how to print and render the document. The feature of the format is that it fixes the document's description which means that it will look the same no matter who and from what operational system opens it.

BMP What is BMP File Format

Bitmap Image File or BMP is a raster-saving image format. It is used to save bitmap digital images and is capable to store 2d graphics in color or monochrome in the high quality as the TIFF format does. It also can contain image information like data compression, color profiles, alpha channels, etc. BMP images are independent of the graphics adapter so the files can be opened on multiple platforms such as Microsoft Windows and Mac.