예제 #1
0
        private async Task FinishRenderAsync(IImageProvider effect, IImageProcessor processor)
        {
            m_bitmapRenderer.Source = effect;

            var thumbnailTargetBitmap = await m_bitmapRenderer.RenderAsync().AsTask().ConfigureAwait(false);

            m_thumbnailCompleteAction(processor, thumbnailTargetBitmap);
        }
예제 #2
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);
        }
        private async void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

            var file = await StorageFile.GetFileFromApplicationUriAsync(new System.Uri("ms-appx:///Assets/defaultImage.jpg"));

            var storageFileImageSource = new StorageFileImageSource(file);
            var asyncImageResource = storageFileImageSource as IAsyncImageResource;
            var imageResource = await asyncImageResource.LoadAsync();
            m_imageSize = imageResource.ImageSize;
            var sepiaEffect = new Lumia.Imaging.Artistic.SepiaEffect(storageFileImageSource);

            SoftwareBitmapRenderer softwareBitmapRenderer = new SoftwareBitmapRenderer(sepiaEffect);

            m_sepiaEffectSoftwareBitmap = await softwareBitmapRenderer.RenderAsync();

            m_canvasControl.Invalidate();
        }
        private async void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

            var file = await StorageFile.GetFileFromApplicationUriAsync(new System.Uri("ms-appx:///Assets/defaultImage.jpg"));

            var storageFileImageSource = new StorageFileImageSource(file);
            var asyncImageResource     = storageFileImageSource as IAsyncImageResource;
            var imageResource          = await asyncImageResource.LoadAsync();

            m_imageSize = imageResource.ImageSize;
            var sepiaEffect = new Lumia.Imaging.Artistic.SepiaEffect(storageFileImageSource);

            SoftwareBitmapRenderer softwareBitmapRenderer = new SoftwareBitmapRenderer(sepiaEffect);

            m_sepiaEffectSoftwareBitmap = await softwareBitmapRenderer.RenderAsync();

            m_canvasControl.Invalidate();
        }
예제 #5
0
        private async Task <SoftwareBitmap> LoadPhotoInternalAsync(IImageProvider unnormalizedSource)
        {
            DisposableHelper.TryDisposeAndSetToNull(ref m_source);

            var info = await unnormalizedSource.GetInfoAsync().AsTask().ConfigureAwait(false);

            var unnormalizedSourceSize = info.ImageSize;

            if ((uint)unnormalizedSourceSize.Width == 0 || (uint)unnormalizedSourceSize.Height == 0)
            {
                throw new ArgumentException("Image source appears to be zero sized.");
            }

            // Normalize source bitmap to ~5 MP
            m_sourceSize = NormalizeSourceSize(unnormalizedSourceSize);

            using (var bitmapRenderer = new SoftwareBitmapRenderer(unnormalizedSource))
            {
                bitmapRenderer.Size          = m_sourceSize;
                bitmapRenderer.OutputOption  = OutputOption.PreserveAspectRatio;
                bitmapRenderer.RenderOptions = RenderOptions.Cpu;

                var normalizedSourceBitmap = await bitmapRenderer.RenderAsync().AsTask().ConfigureAwait(false);

                m_source = new SoftwareBitmapImageSource(normalizedSourceBitmap);
            }

            using (var bitmapRenderer = new SoftwareBitmapRenderer(m_source))
            {
                bitmapRenderer.Size          = PreviewSize;
                bitmapRenderer.OutputOption  = OutputOption.PreserveAspectRatio;
                bitmapRenderer.RenderOptions = RenderOptions.Cpu;

                return(await bitmapRenderer.RenderAsync().AsTask().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);
        }
        private async Task<SoftwareBitmap> LoadPhotoInternalAsync(IImageProvider unnormalizedSource)
        {
            DisposableHelper.TryDisposeAndSetToNull(ref m_source);

            var info = await unnormalizedSource.GetInfoAsync().AsTask().ConfigureAwait(false);
            var unnormalizedSourceSize = info.ImageSize;

            if ((uint)unnormalizedSourceSize.Width == 0 || (uint)unnormalizedSourceSize.Height == 0)
            {
                throw new ArgumentException("Image source appears to be zero sized.");
            }

            // Normalize source bitmap to ~5 MP
            m_sourceSize = NormalizeSourceSize(unnormalizedSourceSize);

			using(var bitmapRenderer = new SoftwareBitmapRenderer(unnormalizedSource))
            {
                bitmapRenderer.Size = m_sourceSize;
                bitmapRenderer.OutputOption = OutputOption.PreserveAspectRatio;
                bitmapRenderer.RenderOptions = RenderOptions.Cpu;

                var normalizedSourceBitmap = await bitmapRenderer.RenderAsync().AsTask().ConfigureAwait(false);

                m_source = new SoftwareBitmapImageSource(normalizedSourceBitmap);
            }

            using(var bitmapRenderer = new SoftwareBitmapRenderer(m_source))
            {
                bitmapRenderer.Size = PreviewSize;
                bitmapRenderer.OutputOption = OutputOption.PreserveAspectRatio;
                bitmapRenderer.RenderOptions = RenderOptions.Cpu;
                
                return await bitmapRenderer.RenderAsync().AsTask().ConfigureAwait(false);
            }
		}