This gist shows code snippet on how to convert JPG to PNG format using Aspose.Imaging Cloud SDK for .NET.
For more information, please visit
This gist shows code snippet on how to convert JPG to PNG format using Aspose.Imaging Cloud SDK for .NET.
For more information, please visit
// Get ClientID from https://dashboard.aspose.cloud/ | |
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3"; | |
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa"; | |
// create an instance of ImagingApi | |
ImagingApi imagingApi= new ImagingApi( clientSecret,clientID,"https://api.aspose.cloud/"); | |
// 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 | |
imagingApi.UploadFile(uploadFileRequest); | |
} | |
try | |
{ | |
// 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 !"); | |
Console.ReadKey(); | |
} | |
// 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); | |
responseStream.CopyTo(fileStream); | |
fileStream.Close(); | |
} |
Code snippets for converting JPG to PNG using Aspose.Imaging Cloud SDK For .NET |