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);
                }
            }
        }
Example #2
0
        /// <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();
            }
        }