Created
June 9, 2024 21:06
-
-
Save aspose-cloud-kb/339477c0f9ac0067d47b03bc938b113b to your computer and use it in GitHub Desktop.
Convert JPG to TIFF with NET REST API. https://kb.aspose.cloud/imaging/net/convert-jpg-to-tiff-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 JpgToTiffConverter | |
{ | |
public void JpgToTiff() | |
{ | |
var clientID = "Client ID"; | |
var clientSecret = "Client Secret"; | |
var apiBaseUrl = "https://api.aspose.cloud"; | |
var localPath = "C:/Words/"; | |
var jpgToTiffImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl); | |
// Source and output file names | |
var inputFileName = "Source.jpg"; | |
var outputFileName = "JpgtoTiff.tiff"; | |
var outputFormat = "tiff"; | |
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 image to Cloud Storage | |
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open); | |
inpuFileStream.Position = 0; | |
var uploadJpgFileRequest = new UploadFileRequest(inputFileName, inpuFileStream, null); | |
jpgToTiffImageApi.UploadFile(uploadJpgFileRequest); | |
var convertJpgToTiffRequest = new ConvertImageRequest(inputFileName, outputFormat, | |
remoteFolder, remoteStorage); | |
var tiffDataStream = jpgToTiffImageApi.ConvertImage(convertJpgToTiffRequest); | |
tiffDataStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat)) | |
{ | |
tiffDataStream.Seek(0, SeekOrigin.Begin); | |
tiffDataStream.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