Partilhar via


Visão Geral de Efeitos de Bitmap

Bitmap effects enable designers and developers to apply visual effects to rendered Windows Presentation Foundation (WPF) content. Por exemplo, efeitos de bitmap permitem que você aplique facilmente uma DropShadowBitmapEffect efeito ou um efeito de Desfoque para uma imagem ou um botão.

Observação importanteImportante

No .NET Framework 4 ou posterior, o BitmapEffect classe é obsoleta.Se você tentar usar o BitmapEffect classe, você receberá uma exceção obsoleto.A alternativa não obsoleta para a BitmapEffect classe é o Effect classe.Na maioria das situações, o Effect classe é significativamente mais rápido.

Este tópico contém as seguintes seções.

  • WPF Bitmap Effects
  • How to Apply an Effect
  • Creating Custom Effects
  • Tópicos relacionados

WPF Bitmap Effects

Efeitos bitmap (BitmapEffect objeto) são pixels simples operações de processamento. A bitmap effect takes a BitmapSource as an input and produces a new 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 Radius of BlurBitmapEffect.

As a special case, in WPF, effects can be set as properties on live Visual objects, such as a Button or TextBox. The pixel processing is applied and rendered at run-time. In this case, at the time of rendering, a Visual is automatically converted to its BitmapSource equivalent and is fed as input to the BitmapEffect. The output replaces the Visual object's default rendering behavior. É por isso que BitmapEffect objetos forçar elementos visuais para processar no software ou apenas seja Nenhuma aceleração de hardware de elementos visuais quando efeitos são aplicados.

Observação

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.

Observação

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

BitmapEffect is a property on Visual. Aplicação, portanto, de efeitos visuais, como um Button, Image, DrawingVisual, ou UIElement, que é tão fácil quanto definir uma propriedade. BitmapEffectpode ser definida como um único BitmapEffect objeto ou vários efeitos que podem ser encadeados usando o BitmapEffectGroup objeto.

The following example demonstrates how to apply a BitmapEffect in Extensible Application Markup Language (XAML).

<Button  Width="200">You Can't Read This!
  <Button.BitmapEffect>

  <!-- <BitmapEffectGroup> would go here if you wanted to apply more 
         then one effect to the Button. However, in this example only  
         one effect is being applied so BitmapEffectGroup does not need  
         to be included. -->

    <!-- The larger the Radius, the more blurring. The default range is 20.
         In addition, the KernelType is set to a box kernel. A box kernel
         creates less disruption (less blur) then the default Gaussian kernel. -->
    <BlurBitmapEffect Radius="10" KernelType="Box" />

  </Button.BitmapEffect>
</Button>

The following example demonstrates how to apply a BitmapEffect in code.

// Get a reference to the Button.
Button myButton = (Button)sender;

// Initialize a new BlurBitmapEffect that will be applied
// to the Button.
BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();

// Set the Radius property of the blur. This determines how 
// blurry the effect will be. The larger the radius, the more
// blurring. 
myBlurEffect.Radius = 10;

// Set the KernelType property of the blur. A KernalType of "Box"
// creates less blur than the Gaussian kernal type.
myBlurEffect.KernelType = KernelType.Box;

// Apply the bitmap effect to the Button.
myButton.BitmapEffect = myBlurEffect;

Observação

When a BitmapEffect is applied to a layout container, such as DockPanel or 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. Para o material de referência adicional para criar efeitos de bitmap personalizado, consulte o Efeito de Bitmap do WPF não gerenciado documentação.

Consulte também

Referência

BitmapEffectGroup

BitmapEffectInput

BitmapEffectCollection

Unmanaged WPF Bitmap Effect

Conceitos

Visão geral sobre imagens

Segurança (WPF)

WPF Graphics Rendering Overview

Otimização de desempenho: 2D Graphics and Imaging