Files
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

6.0 KiB

title, ms.date, ms.topic, helpviewer_keywords, ms.assetid
title ms.date ms.topic helpviewer_keywords ms.assetid
Bitmap Effects Overview 03/30/2017 overview
bitmap effects [WPF]
23cb338e-4b59-4b52-b294-96431f9c9568

Bitmap Effects Overview

Bitmap effects enable designers and developers to apply visual effects to rendered Windows Presentation Foundation (WPF) content. For example, bitmap effects allow you to easily apply a xref:System.Windows.Media.Effects.DropShadowBitmapEffect effect or a blur effect to an image or a button.

Important

In the .NET Framework 4 or later, the xref:System.Windows.Media.Effects.BitmapEffect class is obsolete. If you try to use the xref:System.Windows.Media.Effects.BitmapEffect class, you will get an obsolete exception. The non-obsolete alternative to the xref:System.Windows.Media.Effects.BitmapEffect class is the xref:System.Windows.Media.Effects.Effect class. In most situations, the xref:System.Windows.Media.Effects.Effect class is significantly faster.

WPF Bitmap Effects

Bitmap effects (xref:System.Windows.Media.Effects.BitmapEffect object) are simple pixel processing operations. A bitmap effect takes a xref:System.Windows.Media.Imaging.BitmapSource as an input and produces a new xref:System.Windows.Media.Imaging.BitmapSource after applying the effect, such as a blur or drop shadow. Each bitmap effect exposes properties that can control the filtering properties, such as xref:System.Windows.Media.Effects.BlurBitmapEffect.Radius%2A of xref:System.Windows.Media.Effects.BlurBitmapEffect.

As a special case, in WPF, effects can be set as properties on live xref:System.Windows.Media.Visual objects, such as a xref:System.Windows.Controls.Button or xref:System.Windows.Controls.TextBox. The pixel processing is applied and rendered at run-time. In this case, at the time of rendering, a xref:System.Windows.Media.Visual is automatically converted to its xref:System.Windows.Media.Imaging.BitmapSource equivalent and is fed as input to the xref:System.Windows.Media.Effects.BitmapEffect. The output replaces the xref:System.Windows.Media.Visual object's default rendering behavior. This is why xref:System.Windows.Media.Effects.BitmapEffect objects force visuals to render in software only i.e. no hardware acceleration on visuals when effects are applied.

Note

WPF bitmap effects are rendered in software mode. Any object that applies an effect will also be rendered in software. Performance is degraded the most when using Bitmap effects on large visuals or animating properties of a Bitmap effect. This is not to say that you should not use Bitmap effects in this way at all, but you should use caution and test thoroughly to ensure that your users are getting the experience you expect.
[!NOTE] WPF bitmap effects do not support partial trust execution. An application must have full trust permissions to use bitmap effects.

How to Apply an Effect

xref:System.Windows.Media.Effects.BitmapEffect is a property on xref:System.Windows.Media.Visual. Therefore applying effects to Visuals, such as a xref:System.Windows.Controls.Button, xref:System.Windows.Controls.Image, xref:System.Windows.Media.DrawingVisual, or xref:System.Windows.UIElement, is as easy as setting a property. xref:System.Windows.UIElement.BitmapEffect%2A can be set to a single xref:System.Windows.Media.Effects.BitmapEffect object or multiple effects can be chained by using the xref:System.Windows.Media.Effects.BitmapEffectGroup object.

The following example demonstrates how to apply a xref:System.Windows.Media.Effects.BitmapEffect in Extensible Application Markup Language (XAML).

[!code-xamlEffectsGallery_snip#BlurSimpleExampleInline]

The following example demonstrates how to apply a xref:System.Windows.Media.Effects.BitmapEffect in code.

[!code-csharpEffectsGallery_snip#CodeBehindBlurCodeBehindExampleInline]

Note

When a xref:System.Windows.Media.Effects.BitmapEffect is applied to a layout container, such as xref:System.Windows.Controls.DockPanel or xref:System.Windows.Controls.Canvas, the effect is applied to the visual tree of the element or visual, including all of its child elements.

Creating Custom Effects

WPF also provides unmanaged interfaces to create custom effects that can be used in managed WPF applications. For additional reference material for creating custom bitmap effects, see the Unmanaged WPF Bitmap Effect documentation.

See also