public void CreateGrayscaleedImageTest(string formatExtension, bool saveResultToStorage)
        {
            foreach (StorageFile inputFile in BasicInputTestFiles.Where(f => f.Name.EndsWith(formatExtension)))
            {
                string outName = $"{inputFile.Name}_grayscale.{formatExtension}";

                this.TestPostRequest(
                    "GrayscaleImageTest",
                    saveResultToStorage,
                    $"Input image: {inputFile.Name}; Output format: {formatExtension};",
                    inputFile.Name,
                    outName,
                    delegate(Stream inputStream, string outPath)
                {
                    var request = new CreateGrayscaledImageRequest(inputStream, outPath, TestStorage);
                    return(ImagingApi.CreateGrayscaledImage(request));
                },
                    delegate(ImagingResponse originalProperties, ImagingResponse resultProperties,
                             Stream resultStream)
                {
                    if (!saveResultToStorage)
                    {
                        Assert.NotNull(resultStream);
                        Assert.IsTrue(resultStream.Length > 0);
                    }
                    else
                    {
                        Assert.IsTrue(originalProperties.BitsPerPixel == resultProperties.BitsPerPixel);
                    }
                },
                    TempFolder,
                    TestStorage);
            }
        }
Пример #2
0
        /// <summary>
        /// Grayscales an image. Image data is passed in a request stream.
        /// </summary>
        public void CreateGrayscaledImageFromRequestBody()
        {
            Console.WriteLine("Grayscales the image from request body");

            using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
            {
                string storage = null; // We are using default Cloud Storage
                string outPath = null; // Path to updated file (if this is empty, response contains streamed image)

                var request = new CreateGrayscaledImageRequest(inputImageStream, outPath, storage);

                Console.WriteLine($"Call CreateGrayscale Image");

                using (Stream updatedImage = this.ImagingApi.CreateGrayscaledImage(request))
                {
                    SaveUpdatedSampleImageToOutput(updatedImage, true, SaveImageFormat);
                }
            }

            Console.WriteLine();
        }