示例#1
0
        /// <summary>
        ///     Perform scaling, cropping and flipping of an image in a single request. Image data is passed in a request stream.
        /// </summary>
        public void CreateUpdatedImageFromRequestBody()
        {
            Console.WriteLine("Update parameters of an image from request body");

            using (var inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
            {
                // Please refer to https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats#SupportedFileFormats-Update
                // for possible output formats
                var    format           = "pdf";
                int?   newWidth         = 300;
                int?   newHeight        = 450;
                int?   x                = 10;
                int?   y                = 10;
                int?   rectWidth        = 200;
                int?   rectHeight       = 300;
                var    rotateFlipMethod = "Rotate90FlipX";
                string outPath          = null; // Path to updated file (if this is empty, response contains streamed image)
                string storage          = null; // We are using default Cloud Storage

                var postImageUpdateRequest = new CreateUpdatedImageRequest(inputImageStream, newWidth, newHeight, x, y, rectWidth, rectHeight, rotateFlipMethod, format, outPath, storage);

                Console.WriteLine(
                    $"Call CreateUpdatedImage with params: new width:{newWidth}, new height:{newHeight}, x:{x}, y:{y}, rect width:{rectWidth}, rectHeight:{rectHeight}, rotate/flip method:{rotateFlipMethod}, format:{format}");

                using (var updatedImage = ImagingApi.CreateUpdatedImage(postImageUpdateRequest))
                {
                    SaveUpdatedSampleImageToOutput(updatedImage, true);
                }
            }

            Console.WriteLine();
        }
示例#2
0
        public void CreateUpdatedImageTest(string formatExtension, bool saveResultToStorage, params string[] additionalExportFormats)
        {
            string name             = null;
            int?   newWidth         = 300;
            int?   newHeight        = 450;
            int?   x                = 10;
            int?   y                = 10;
            int?   rectWidth        = 200;
            int?   rectHeight       = 300;
            string rotateFlipMethod = "Rotate90FlipX";
            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}_update.{format ?? formatExtension.Substring(1)}";

                    this.TestPostRequest(
                        "CreateUpdatedImageTest",
                        saveResultToStorage,
                        $"Input image: {name}; Output format: {format ?? "null"}; New width: {newWidth}; New height: {newHeight}; Rotate/flip method: {rotateFlipMethod}; " +
                        $"X: {x}; Y: {y}; Rect width: {rectWidth}; Rect height: {rectHeight}",
                        name,
                        outName,
                        delegate(Stream inputStream, string outPath)
                    {
                        var request = new CreateUpdatedImageRequest(inputStream, newWidth, newHeight, x, y, rectWidth, rectHeight, rotateFlipMethod, format, outPath, storage);
                        return(ImagingApi.CreateUpdatedImage(request));
                    },
                        delegate(ImagingResponse originalProperties, ImagingResponse resultProperties, Stream resultStream)
                    {
                        Assert.AreEqual(rectHeight, resultProperties.Width);
                        Assert.AreEqual(rectWidth, resultProperties.Height);
                    },
                        folder,
                        storage);
                }
            }
        }