public ThumbnailRenderer(Size thumbnailSize, Action <IImageProcessor, SoftwareBitmap> thumbnailCompleteAction) { m_thumbnailSize = thumbnailSize; m_thumbnailCompleteAction = thumbnailCompleteAction; m_bitmapRenderer = new SoftwareBitmapRenderer(); m_bitmapRenderer.Size = thumbnailSize; }
public ThumbnailRenderer(Size thumbnailSize, Action<IImageProcessor, SoftwareBitmap> thumbnailCompleteAction) { m_thumbnailSize = thumbnailSize; m_thumbnailCompleteAction = thumbnailCompleteAction; m_bitmapRenderer = new SoftwareBitmapRenderer(); m_bitmapRenderer.Size = thumbnailSize; }
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(); }
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); } }
/// <summary> /// Initializes a new instance of the <see cref="BarcodeWriterSoftwareBitmap"/> class. /// </summary> public BarcodeWriterSoftwareBitmap() { Renderer = new SoftwareBitmapRenderer(); }