private Bitmap RenderImage() { Bitmap bitmap = TokenControl.RenderVisual(TokenControl.ZoomControl); //Apply the special filter. BitmapHelper.AddFilter(bitmap, _vm.SpecialFilterColor, _specialFilter); // Modify the rendered image. if (_overlayInfo != null) { var overlay = ImageLoader.LoadBitmapFromFile(_overlayInfo.Info.File, TokenControl.ImageResolutionWidth, TokenControl.ImageResolutionHeight); BitmapHelper.AddFilter(overlay, _overlayTintColor, _overlayBlendFilter); if (!string.IsNullOrWhiteSpace(_overlayInfo.Info.Mask)) { BitmapHelper.ApplyMaskToImage(overlay, ImageLoader.LoadBitmapFromFile(_overlayInfo.Info.Mask, TokenControl.ImageResolutionWidth, TokenControl.ImageResolutionHeight)); } BitmapHelper.AddLayerToImage(bitmap, overlay); } if (_borderInfo != null) { if (!string.IsNullOrWhiteSpace(_borderInfo.Info.Mask)) { BitmapHelper.ApplyMaskToImage(bitmap, ImageLoader.LoadBitmapFromFile(_borderInfo.Info.Mask, TokenControl.ImageResolutionWidth, TokenControl.ImageResolutionHeight)); } var border = ImageLoader.LoadBitmapFromFile(_borderInfo.Info.File, TokenControl.ImageResolutionWidth, TokenControl.ImageResolutionHeight); BitmapHelper.AddFilter(border, _borderTintColor, _borderBlendFilter); BitmapHelper.AddLayerToImage(bitmap, border); //Draw the border } if (TokenControl.ZoomControl_Text.Visibility == Visibility.Visible) { Bitmap text = TokenControl.RenderVisual(TokenControl.ZoomControl_Text); BitmapHelper.AddLayerToImage(bitmap, text); } if (_vm.Autocrop) { bitmap = BitmapHelper.Autocrop(bitmap); } //Since we just spent time rendering the image, we might as well update the preview even if the user didn't ask for that specifically. _preWindow?.SetImage(bitmap); return(bitmap); }