Exemplo n.º 1
0
        public async Task UpdateThumbnailsAsync()
        {
#if DEBUG
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            var fullSizedSourceBitmap = ((SoftwareBitmapImageSource)m_source).SoftwareBitmap;

            SoftwareBitmap thumbnailSizedSourceBitmap;

            // Some image processors can render at thumbnail resolution. Prepare a scaled down source for them.
            using (var thumbnailSourceRenderer = new SoftwareBitmapRenderer(m_source))
            {
                thumbnailSourceRenderer.Size         = ThumbnailSize;
                thumbnailSourceRenderer.OutputOption = OutputOption.PreserveAspectRatio;
                thumbnailSizedSourceBitmap           = await thumbnailSourceRenderer.RenderAsync().AsTask().ConfigureAwait(false);
            }

            var imageProcessors = await m_createImageProcessorsTask.ConfigureAwait(false);

            var batchTasks = Enumerable.Repeat((Task)Task.FromResult(false), 4).ToArray();

            var thumbnailRenderers = new ThumbnailRenderer[batchTasks.Length];
            for (int i = 0; i < thumbnailRenderers.Length; ++i)
            {
                thumbnailRenderers[i] = new ThumbnailRenderer(ThumbnailSize, OnThumbnailComplete);
            }

            for (int imageProcessorIndex = 0; imageProcessorIndex < imageProcessors.Count; imageProcessorIndex++)
            {
                var imageProcessor = imageProcessors[imageProcessorIndex];

                var sourceBitmap = imageProcessor.CanRenderAtPreviewSize
                    ? thumbnailSizedSourceBitmap
                    : thumbnailSizedSourceBitmap;// fullSizedSourceBitmap;

                var taskIndex = imageProcessorIndex % batchTasks.Length;

                batchTasks[taskIndex] = batchTasks[taskIndex].ContinueWith(_ =>
                {
                    return(thumbnailRenderers[taskIndex].RenderAsync(sourceBitmap, imageProcessor));
                }, TaskContinuationOptions.ExecuteSynchronously);
            }

            await Task.WhenAll(batchTasks).ConfigureAwait(false);
        }
        public async Task UpdateThumbnailsAsync()
        {
#if DEBUG
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
			var fullSizedSourceBitmap = ((SoftwareBitmapImageSource)m_source).SoftwareBitmap;

			SoftwareBitmap thumbnailSizedSourceBitmap;

			// Some image processors can render at thumbnail resolution. Prepare a scaled down source for them.
			using (var thumbnailSourceRenderer = new SoftwareBitmapRenderer(m_source))
			{
				thumbnailSourceRenderer.Size = ThumbnailSize;
				thumbnailSourceRenderer.OutputOption = OutputOption.PreserveAspectRatio;
				thumbnailSizedSourceBitmap = await thumbnailSourceRenderer.RenderAsync().AsTask().ConfigureAwait(false);
			}

			var imageProcessors = await m_createImageProcessorsTask.ConfigureAwait(false);

            var batchTasks = Enumerable.Repeat((Task)Task.FromResult(false), 4).ToArray();

            var thumbnailRenderers = new ThumbnailRenderer[batchTasks.Length];
            for(int i = 0; i < thumbnailRenderers.Length; ++i)
            {
                thumbnailRenderers[i] = new ThumbnailRenderer(ThumbnailSize, OnThumbnailComplete);
            }

            for (int imageProcessorIndex = 0; imageProcessorIndex < imageProcessors.Count; imageProcessorIndex++)
            {
                var imageProcessor = imageProcessors[imageProcessorIndex];

                var sourceBitmap = imageProcessor.CanRenderAtPreviewSize
                    ? thumbnailSizedSourceBitmap
                    : thumbnailSizedSourceBitmap;// fullSizedSourceBitmap;

                var taskIndex = imageProcessorIndex % batchTasks.Length;

                batchTasks[taskIndex] = batchTasks[taskIndex].ContinueWith(_ =>
                    {
                        return thumbnailRenderers[taskIndex].RenderAsync(sourceBitmap, imageProcessor);

                    }, TaskContinuationOptions.ExecuteSynchronously);
            }

            await Task.WhenAll(batchTasks).ConfigureAwait(false);
        }