Exemplo n.º 1
0
        public void CreateImageFrameRangeTest(string formatExtension, bool saveResultToStorage)
        {
            var startFrameId = 0;
            var endFrameId   = 1;
            var folder       = TempFolder;
            var storage      = TestStorage;
            var exportFormat = GetExportFormat(formatExtension, false);

            foreach (var inputFile in MultipageInputTestFiles)
            {
                var name = inputFile.Name;
                if (inputFile.Name.EndsWith(formatExtension))
                {
                }
                else
                {
                    continue;
                }

                var outName = $"{name}_frame_range{exportFormat}";

                TestPostRequest(
                    "CreateImageFrameRangeTest",
                    saveResultToStorage,
                    $"Input image: {name}; Start frame id: {startFrameId}; End frame id: {endFrameId}",
                    name,
                    outName,
                    delegate(Stream inputStream, string outPath)
                {
                    var request = new CreateImageFrameRangeRequest(inputStream, startFrameId, endFrameId,
                                                                   outPath: outPath, storage: storage);
                    return(ImagingApi.CreateImageFrameRange(request));
                },
                    delegate(ImagingResponse properties, ImagingResponse resultProperties, Stream stream)
                {
                    Assert.IsNotNull(resultProperties);
                    if (_formatsWithoutProperties.Contains(exportFormat))
                    {
                        return;
                    }

                    var propertiesName         = GetPropertiesName(exportFormat);
                    var resultFormatProperties =
                        typeof(ImagingResponse)
                        .GetProperty(propertiesName, BindingFlags.Instance | BindingFlags.Public)
                        ?.GetValue(resultProperties, null);
                    Assert.IsNotNull(resultFormatProperties);
                },
                    folder,
                    storage);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Get frame range from existing image. Image data is passed in a request stream.
        /// </summary>
        public void CreateImageFrameRangeFromRequestBody()
        {
            Console.WriteLine("Get separate frame from existing image from request body");

            using (var inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
            {
                int?   startFrameId = 1;    // Index of the first frame in range
                int?   endFrameId   = 4;    // Index of the last frame in range
                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 createImageFrameRangeRequest =
                    new CreateImageFrameRangeRequest(inputImageStream, startFrameId, endFrameId, outPath: outPath, storage: storage);

                Console.WriteLine($"Call CreateImageFrame with params: start frame Id:{startFrameId}, end frame Id:{endFrameId}");

                using (var imageFrame = ImagingApi.CreateImageFrameRange(createImageFrameRangeRequest))
                {
                    SaveUpdatedImageToOutput("FrameRangeFromRequest.djvu", imageFrame);
                }
            }

            Console.WriteLine();
        }