Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-cloud-kb/5209da5c7df4cd52becab42fd83427d3 to your computer and use it in GitHub Desktop.
Save aspose-cloud-kb/5209da5c7df4cd52becab42fd83427d3 to your computer and use it in GitHub Desktop.
using Aspose.Imaging.Cloud.Sdk.Api;
using Aspose.Imaging.Cloud.Sdk.Model.Requests;
using Aspose.Imaging.Cloud.Sdk.Model;
using System;
using System.IO;
namespace Kb_Aspose.KB
{
public class PngToJpgConverter
{
public void PngToJpg()
{
var clientID = "Client ID";
var clientSecret = "Client Secret";
var apiBaseUrl = "https://api.aspose.cloud";
var localPath = "C:/Words/";
var pngToJpgImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl);
// Source and output file names
var inputFileName = "Source.png";
var outputFileName = "PngtoJpg.jpg";
var outputFormat = "jpg";
var remoteFolder = null; // source file is saved at the root of the storage
var remoteStorage = null; // remote cloud Storage place name
try
{
// Upload the local PNG image to Cloud Storage
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open);
inpuFileStream.Position = 0;
var uploadPngFileReq = new UploadFileRequest(inputFileName, inpuFileStream, null);
pngToJpgImageApi.UploadFile(uploadPngFileReq);
var convertPngToJpgRequest = new ConvertImageRequest(inputFileName, outputFormat,
remoteFolder, remoteStorage);
var jpgDataStream = pngToJpgImageApi.ConvertImage(convertPngToJpgRequest);
jpgDataStream.Position = 0;
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat))
{
jpgDataStream.Seek(0, SeekOrigin.Begin);
jpgDataStream.CopyTo(fileStream);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment