private async Task LoadOutputVirtualBitmap() { if (OutputVirtualBitmap != null) { OutputVirtualBitmap.Dispose(); OutputVirtualBitmap = null; } //LoadedImageInfo = ""; OutputVirtualBitmap = await CanvasVirtualBitmap.LoadAsync(OutputImageCanvas.Device, OutputImageStream, CanvasVirtualBitmapOptions.None); if (OutputImageCanvas == null) { // This can happen if the page is unloaded while LoadAsync is running return; } ImageResolution.Text = InputVirtualBitmap.Bounds.Width + " x " + InputVirtualBitmap.Bounds.Height + " | " + OutputVirtualBitmap.Bounds.Width + " x " + OutputVirtualBitmap.Bounds.Height; var size = OutputVirtualBitmap.Size; OutputImageCanvas.Width = size.Width * (Zoom + 1); OutputImageCanvas.Height = size.Height * (Zoom + 1); OutputImageCanvas.Invalidate(); //LoadedImageInfo = string.Format("{0}x{1} image, is {2}CachedOnDemand", size.Width, size.Height, virtualBitmap.IsCachedOnDemand ? "" : "not "); }
private void Page_Unloaded(object sender, RoutedEventArgs e) { InputImageCanvas.RemoveFromVisualTree(); OutputImageCanvas.RemoveFromVisualTree(); InputImageCanvas = null; OutputImageCanvas = null; }
private void Page_SizeChanged(object sender, SizeChangedEventArgs e) { InputImageCanvas.Invalidate(); OutputImageCanvas.Invalidate(); InputCanvasScrollViewer.MaxWidth = double.MaxValue; InputCanvasScrollViewer.MaxHeight = double.MaxValue; OutputCanvasScrollViewer.MaxWidth = double.MaxValue; OutputCanvasScrollViewer.MaxHeight = double.MaxValue; }
private void OutputImageCanvas_RegionsInvalidated(Microsoft.Graphics.Canvas.UI.Xaml.CanvasVirtualControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasRegionsInvalidatedEventArgs args) { foreach (var region in args.InvalidatedRegions) { using (var ds = OutputImageCanvas.CreateDrawingSession(region)) { if (OutputVirtualBitmap != null) { ds.DrawImage(OutputVirtualBitmap, new Rect(0, 0, OutputVirtualBitmap.Bounds.Width * Zoom, OutputVirtualBitmap.Bounds.Height * Zoom), new Rect(0, 0, OutputVirtualBitmap.Bounds.Width, OutputVirtualBitmap.Bounds.Height), 1.0f, CanvasImageInterpolation.NearestNeighbor); } } } }
private void OutputCanvasScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e) => OutputImageCanvas.Invalidate();