Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active November 1, 2021 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/00f84b74f953dbcd583b02997e474b55 to your computer and use it in GitHub Desktop.
Save aspose-cloud/00f84b74f953dbcd583b02997e474b55 to your computer and use it in GitHub Desktop.
This Gist contains code snippets related to conversion SVG file to PNG format using Aspose.Imaging Cloud SDK for .NET
This Gist contains code snippets related to conversion SVG file to PNG format using Aspose.Imaging Cloud SDK for .NET
// For complete examples, please visit https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
// Get client credentials from https://dashboard.aspose.cloud/
string clientSecret = "d757548a9f2558c39c2feebdf85b4c44";
string clientID = "4db2f826-bf9c-42e7-8b2a-8cbca2d15553";
// create an object of DiagramApi
ImagingApi imagingApi = new ImagingApi(clientSecret,clientID, "https://api.aspose.cloud/");
// name of input SVG file
String inputFileName = "trashloader2.svg";
// resultant file format
String newFormat = "png";
// name of output file
String newFileName = "Converted.png";
try
{
// load the file from local drive
using (var inputStream = System.IO.File.OpenRead(@"C:\Users\shahbnay\Downloads\" + inputFileName))
{
// create file upload request
UploadFileRequest request = new UploadFileRequest(inputFileName, inputStream);
// upload file to default Cloud storage
imagingApi.UploadFile(request);
// create an instance for Image Conversion
var response = new ConvertImageRequest(inputFileName,newFormat);
// initiate the image conversion operation
var responseStream = imagingApi.ConvertImage(response);
// save the stream instance as file on local storage
saveToDisk(responseStream, @"C:\Users\shahbnay\Downloads\" + newFileName);
}
catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
static void saveToDisk(Stream responseStream, String resultantFile)
{
var fileStream = File.Create(resultantFile);
responseStream.Seek(0, SeekOrigin.Begin);
responseStream.CopyTo(fileStream);
fileStream.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment