void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { if (photo.SourceBitmap == null) { return; } var drawingSession = args.DrawingSession; drawingSession.Units = CanvasUnits.Pixels; drawingSession.Blend = CanvasBlend.Copy; // Draw the main photo image. ICanvasImage image; if (editingRegion != null) { image = cachedImage.Get() ?? cachedImage.Cache(photo, photo.GetImage()); } else { image = photo.GetImage(); } drawingSession.DrawImage(image); // Highlight the current region (if any). lastDrawnZoomFactor = null; foreach (var edit in photo.Edits) { if (edit.DisplayRegionMask(drawingSession, scrollView.ZoomFactor, editingRegion != null)) { lastDrawnZoomFactor = scrollView.ZoomFactor; } } // Display any in-progress region edits. if (editingRegion != null) { editingRegion.DisplayRegionEditInProgress(drawingSession, regionPoints, scrollView.ZoomFactor); } }
public ICanvasImage GetRegionMask() { // Do we already have a cached version of this mask? ICanvasImage mask = cachedRegionMask.Get(regionFeather, regionDilate); if (mask == null) { mask = regionMask; // Expand or contract the selection? if (regionDilate != 0) { mask = new MorphologyEffect { Source = new BorderEffect { Source = mask }, Mode = (regionDilate > 0) ? MorphologyEffectMode.Dilate : MorphologyEffectMode.Erode, Height = Math.Abs(regionDilate), Width = Math.Abs(regionDilate) }; } // Feather the selection? if (regionFeather > 0) { mask = new GaussianBlurEffect { Source = mask, BlurAmount = regionFeather, BorderMode = EffectBorderMode.Hard }; } // If this mask was expensive to compute, cache it now. if (mask != regionMask) { mask = cachedRegionMask.Cache(Parent, mask, regionFeather, regionDilate); } } return(mask); }