Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code snippets for converting JPG to PNG using C#
// Get ClientID from
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// path of input JPEG image
string imageFile = "jpg-to-png.jpeg";
// output file format
string format = "png";
// resultant file name
string resultantFile = "converted.png";
// load the file from local drive
using (var file = System.IO.File.OpenRead("/Users/nshahbaz/Desktop/" + imageFile))
var uploadFileRequest = new UploadFileRequest(imageFile, file);
// Upload original document to Cloud Storage
// Create ImageRequest
var request = new ConvertImageRequest(imageFile, format, null, null);
// initiate the conversion operation
Stream updatedImage = imagingApi.ConvertImage(request);
// print success message if conversion is successful
if (request != null && request.Equals("OK"))
Console.WriteLine("JPG successfully converted to PNG !");
// call the method to save output over system drive
saveToDisk(updatedImage, "/Users/nshahbaz/Desktop/"+resultantFile);
catch (Exception ex)
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
// custom method to save steam object as file instance
public static void saveToDisk(Stream responseStream, String resultantFile)
var fileStream = File.Create(resultantFile);
responseStream.Seek(0, SeekOrigin.Begin);
Code snippets for converting JPG to PNG using Aspose.Imaging Cloud SDK For .NET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment