public void CreateConvertedImageTest(string formatExtension, bool saveResultToStorage, params string[] additionalExportFormats) { string name = null; string folder = TempFolder; string storage = this.TestStorage; string outName = null; List <string> formatsToExport = new List <string>(this.BasicExportFormats); foreach (string additionalExportFormat in additionalExportFormats) { if (!formatsToExport.Contains(additionalExportFormat)) { formatsToExport.Add(additionalExportFormat); } } foreach (StorageFile inputFile in BasicInputTestFiles) { if (inputFile.Name.EndsWith(formatExtension)) { name = inputFile.Name; } else { continue; } foreach (string format in formatsToExport) { outName = $"{name}.{format}"; this.TestPostRequest( "CreateSavedImageAsTest", saveResultToStorage, $"Input image: {name}; Output format: {format}", name, outName, delegate(Stream inputStream, string outPath) { var request = new CreateConvertedImageRequest(inputStream, format, outPath, storage); return(ImagingApi.CreateConvertedImage(request)); }, null, folder, storage); } } }
public void ConvertFromStreamExampleTest() { var config = this.ImagingApi.Configuration; var imagingApi = config.OnPremise ? new ImagingApi(config.ApiBaseUrl, config.ApiVersion, config.DebugMode) : new ImagingApi(config.ClientSecret, config.ClientId, config.ApiBaseUrl); try { // get local image stream using (FileStream localInputImage = File.OpenRead(Path.Combine(LocalTestFolder, "test.png"))) { // convert image from request stream to JPEG and save it to storage // please, use outPath parameter for saving the result to storage var postSaveToStorageRequest = new CreateConvertedImageRequest(localInputImage, "jpg", "ExampleFolderNet/resultImage.jpg", config.OnPremise ? this.TestStorage : null); imagingApi.CreateConvertedImage(postSaveToStorageRequest); // download saved image from storage using (Stream savedFile = imagingApi.DownloadFile(new DownloadFileRequest("ExampleFolderNet/resultImage.jpg", config.OnPremise ? this.TestStorage : null))) { // process resulting image from storage } localInputImage.Seek(0, SeekOrigin.Begin); // convert image from request stream to JPEG and read it from resulting stream // please, set outPath parameter as null to return result in request stream instead of saving to storage var postSaveToStreamRequest = new CreateConvertedImageRequest(localInputImage, "jpg", null, config.OnPremise ? this.TestStorage : null); using (Stream resultPostImageStream = imagingApi.CreateConvertedImage(postSaveToStreamRequest)) { // process resulting image from response stream } } } finally { // remove file from storage imagingApi.DeleteFile(new DeleteFileRequest("ExampleFolderNet/resultImage.jpg", config.OnPremise ? this.TestStorage : null)); } }
/// <summary> /// Export an image to another format. Image data is passed in a request stream. /// </summary> public void CreateSavedImageAsFromRequestBody() { Console.WriteLine("Export an image to another format. Image data is passed in a request body"); using (var inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName))) { // Please refer to https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats#SupportedFileFormats-Export(SaveAs) // for possible output formats var format = "pdf"; string outPath = null; // Path to updated file (if this is empty, response contains streamed image) string storage = null; // Cloud Storage name var request = new CreateConvertedImageRequest(inputImageStream, format, outPath, storage); Console.WriteLine($"Call CreateSavedImageAs with params: format:{format}"); using (var updatedImage = ImagingApi.CreateConvertedImage(request)) { SaveUpdatedSampleImageToOutput(updatedImage, true, format); } Console.WriteLine(); } }