/// <summary> /// Apply a bitmap effect to this RenderBuffer within the area defined by the effect input. /// </summary> public void ApplyEffect(BitmapEffect effect, BitmapEffectInput input) { if (effect == null) { return; } // Rect bounds = ComputeAreaToApplyEffect(input); if (bounds.IsEmpty) { // NOTE: Don't confuse 'bounds' with BitmapEffectInput.AreaToApplyEffect! // An empty area in the Input means to use the entire RenderTarget, and bounds // is the size of the RenderTarget we want to apply the effect to. // At this stage, 'Empty' means that there is nothing to apply an effect to. return; } if (effect is DropShadowBitmapEffect) { ApplyDropShadow(effect as DropShadowBitmapEffect, bounds); } else { throw new NotImplementedException("Haven't implemented the " + effect.GetType().Name + " effect yet"); } }
public override void PushEffect( BitmapEffect effect, BitmapEffectInput effectInput) { _drawingContext.PushEffect( effect, effectInput ); }
public override void PushEffect( BitmapEffect effect, BitmapEffectInput effectInput) { // Ensure the type stack PushTypeStack(PushType.BitmapEffect); // This API has been deprecated, so any BitmapEffect is ignored. }
/// <summary> /// This summary has not been prepared yet. NOSUMMARY - pantal07 /// </summary> public static BitmapEffectInput Absolute(Rect absoluteArea) { BitmapEffectInput input = new BitmapEffectInput(); input.AreaToApplyEffect = absoluteArea; input.AreaToApplyEffectUnits = BrushMappingMode.Absolute; return(input); }
/// <summary> /// This summary has not been prepared yet. NOSUMMARY - pantal07 /// </summary> public static BitmapEffectInput Relative(Rect relativeArea) { BitmapEffectInput input = new BitmapEffectInput(); input.AreaToApplyEffect = relativeArea; input.AreaToApplyEffectUnits = BrushMappingMode.RelativeToBoundingBox; return(input); }
public override void PushEffect( BitmapEffect effect, BitmapEffectInput effectInput) { if (!IsPushNoOp()) { // This API has been deprecated, so any BitmapEffect is ignored. PushPointStack(_point); } }
private static DrawingGroup WalkVisual(Visual visual) { DrawingGroup vd = VisualTreeHelper.GetDrawing(visual); BitmapEffect be = VisualTreeHelper.GetBitmapEffect(visual); BitmapEffectInput bei = VisualTreeHelper.GetBitmapEffectInput(visual); Geometry cg = VisualTreeHelper.GetClip(visual); double op = VisualTreeHelper.GetOpacity(visual); Brush om = VisualTreeHelper.GetOpacityMask(visual); GuidelineSet? gs = GetGuidelines(visual); Transform? tx = GetTransform(visual); DrawingGroup?dg = null; if (be is null && cg is null && om is null && gs is null && tx is null && IsZero(op - 1)) { dg = vd ?? new DrawingGroup(); }
/// <summary> /// Compute the DPI-correct rectangular area that the BitmapEffectInput describes /// </summary> private Rect ComputeAreaToApplyEffect(BitmapEffectInput input) { if (input == null || input.AreaToApplyEffect.IsEmpty) { // Empty area is the same as a null input (use entire RenderTarget). // width and height are already in absolute DPI (no conversion necessary) return(new Rect(0, 0, width, height)); } else { // 'renderedBounds' is already in absolute DPI (no conversion necessary) Rect renderedBounds = RenderedBounds; if (renderedBounds == Rect.Empty) { // No effect can be applied because no pixels are rendered. return(Rect.Empty); } Rect area; if (input.AreaToApplyEffectUnits == BrushMappingMode.RelativeToBoundingBox) { // The DPI conversion happens implicitly because renderedBounds is already adjusted. area = MathEx.ScaleRect(input.AreaToApplyEffect, renderedBounds); } else { area = MathEx.ConvertToAbsolutePixels(input.AreaToApplyEffect); // Absolute is defined as relative to the boundingBox so we need to transform (offset) // its location by the bounding box's location (do not scale by Width/Height) area.X += renderedBounds.X; area.Y += renderedBounds.Y; } area = Rect.Intersect(area, renderedBounds); return(MathEx.InflateToIntegerBounds(area)); } }
public abstract void PushEffect( BitmapEffect effect, BitmapEffectInput effectInput);
public override void PushEffect( BitmapEffect effect, BitmapEffectInput effectInput) { Debug.Assert(false); }
private static Drawing CreateDrawing(Visual visual, bool includeTransform) { DrawingGroup drawingGroup = new DrawingGroup(); System.Windows.Media.Geometry clip = VisualTreeHelper.GetClip(visual); if (clip != null) { drawingGroup.ClipGeometry = clip; } if (includeTransform) { Transform transform = VisualTreeHelper.GetTransform(visual); Vector offset = VisualTreeHelper.GetOffset(visual); Matrix matrix = transform == null ? Matrix.Identity : transform.Value; matrix.Translate(offset.X, offset.Y); if (!matrix.IsIdentity) { drawingGroup.Transform = (Transform) new MatrixTransform(matrix); } } double opacity = VisualTreeHelper.GetOpacity(visual); if (opacity != 1.0) { drawingGroup.Opacity = opacity; } Brush opacityMask = VisualTreeHelper.GetOpacityMask(visual); if (opacityMask != null) { drawingGroup.OpacityMask = opacityMask; } BitmapEffect bitmapEffect = VisualTreeHelper.GetBitmapEffect(visual); if (bitmapEffect != null) { drawingGroup.BitmapEffect = bitmapEffect; } BitmapEffectInput bitmapEffectInput = VisualTreeHelper.GetBitmapEffectInput(visual); if (bitmapEffectInput != null && (!bitmapEffectInput.AreaToApplyEffect.IsEmpty || bitmapEffectInput.Input != BitmapEffectInput.ContextInputSource)) { drawingGroup.BitmapEffectInput = bitmapEffectInput; } Drawing drawing1; if (MakeDrawingBrushCommand.IsMediaElementInstance(visual)) { Rect bounds = VisualTreeHelper.GetDrawing(visual).Bounds; drawing1 = (Drawing) new VideoDrawing() { Rect = bounds }; } else { drawing1 = (Drawing)VisualTreeHelper.GetDrawing(visual); } if (drawing1 != null) { drawingGroup.Children.Add(drawing1); } for (int childIndex = 0; childIndex < VisualTreeHelper.GetChildrenCount((DependencyObject)visual); ++childIndex) { Visual visual1 = VisualTreeHelper.GetChild((DependencyObject)visual, childIndex) as Visual; if (visual1 != null) { Drawing drawing2 = MakeDrawingBrushCommand.CreateDrawing(visual1, true); if (drawing2 != null) { drawingGroup.Children.Add(drawing2); } } } if (drawingGroup.Children.Count == 0) { return((Drawing)null); } if (drawingGroup.Children.Count == 1 && drawingGroup.ClipGeometry == null && (drawingGroup.Transform == null || drawingGroup.Transform.Value.IsIdentity) && (drawingGroup.Opacity == 1.0 && drawingGroup.OpacityMask == null && drawingGroup.BitmapEffect == null)) { return(drawingGroup.Children[0]); } return((Drawing)drawingGroup); }