How to merge multiple PNG files together in C# .NET Framework
2 min readFeb 10, 2020
Today we shall be taking a closer look at how to combine several PNGs into one larger PNG. We are going to use an API shortcut to speed straight to the results.
Installing our API client comes first, which is done by simply running this command in Package Manager Console.
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
Now we can input our PNG files into MergeDocumentPng, as you can see right here:
using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class MergeDocumentPngExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new MergeDocumentApi();var inputFile1 = new System.IO.Stream(); // System.IO.Stream | First input file to perform the operation on.var inputFile2 = new System.IO.Stream(); // System.IO.Stream | Second input file to perform the operation on (more than 2 can be supplied).try{// Merge Multple PNG Files Togetherbyte[] result = apiInstance.MergeDocumentPng(inputFile1, inputFile2);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling MergeDocumentApi.MergeDocumentPng: " + e.Message );}}}}
Our first two files are now combined! We can proceed by simply calling that same function again with our result and the next PNG in our sequence. In this way, the order of our PNGs will be preserved in vertical order.