Last active
June 2, 2024 20:31
Convert JPG to JPEG2000 with NET REST API. https://kb.aspose.cloud/imaging/net/convert-jpg-to-jpeg2000-with-net-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 JpgToJpeg2000Converter | |
{ | |
public void JpgToJpeg2000() | |
{ | |
var clientID = "Client ID"; | |
var clientSecret = "Client Secret"; | |
var apiBaseUrl = "https://api.aspose.cloud"; | |
var localPath = "C:/Words/"; | |
var jpgToJpeg2000ImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl); | |
// Source and output file names | |
var inputFileName = "Source.jpg"; | |
var outputFileName = "JpgtoJpeg2000.jp2"; | |
var outputFormat = "jp2"; | |
var remoteFolder = null; // Input file is saved at the root of the storage | |
var remoteStorage = null; // remote cloud Storage name | |
try | |
{ | |
// Upload the local image to Cloud Storage | |
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open); | |
inpuFileStream.Position = 0; | |
var uploadJpgFileRequest = new UploadFileRequest(inputFileName, inpuFileStream, null); | |
jpgToJpeg2000ImageApi.UploadFile(uploadJpgFileRequest); | |
var convertJpgToJpeg2000Request = new ConvertImageRequest(inputFileName, outputFormat, | |
remoteFolder, remoteStorage); | |
var jp2DataStream = jpgToJpeg2000ImageApi.ConvertImage(convertJpgToJpeg2000Request); | |
jp2DataStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat)) | |
{ | |
jp2DataStream.Seek(0, SeekOrigin.Begin); | |
jp2DataStream.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