BulgeEffect
Magnifies the picture inside a circular lens, or pinches it inwards when Amount is
negative – a magnifying glass one way, a pinch the other.
public class BulgeEffect : ShaderEffect
Inherits from / implements: ShaderEffect
Remarks
Only what falls inside Radius moves, and the displacement eases to nothing at
the rim, so the lens blends into the untouched picture instead of showing as a hard circle. The lens
is measured in relative coordinates, so on an element that is not square it takes the element's
proportions. Animate Amount across zero to go from pinch to bulge in one pass.
Settings
| Property | Range and default |
|---|---|
Strength and direction. Default 0.5; 0 leaves the picture unchanged, negative values pinch, and values above 1 turn the middle of the lens inside out. -1 to 1 is the useful range. | |
Reach of the lens from its centre, as a fraction of the element. Default 0.45. | |
Centre of the lens, in relative coordinates: (0,0) is the top-left corner of the element and (1,1) its bottom-right. Default (0.5,0.5). |
Examples
A magnifier that follows the mouse over a photograph.
<Image Source="Photos/harbour.jpg"
xmlns:fx="clr-namespace:Binarymission.WPF.Shaders.Library.CustomEffects;assembly=Binarymission.WPF.Shaders.Library"
MouseMove="OnPhotoMouseMove">
<Image.Effect>
<fx:BulgeEffect x:Name="Magnifier" Amount="0.7" Radius="0.2" />
</Image.Effect>
</Image>private void OnPhotoMouseMove(object sender, MouseEventArgs e)
{
var photo = (Image)sender;
Point position = e.GetPosition(photo);
Magnifier.CenterXY = new Point(position.X / photo.ActualWidth, position.Y / photo.ActualHeight);
}See also
Members at a glance
| Constructors | |
|---|---|
BulgeEffect | Creates the effect with its default settings: Amount 0.5, Radius 0.45,
CenterXY (0.5,0.5). |
| Properties | |
Amount | Gets or sets how strongly the lens distorts the picture, and in which direction. |
CenterXY | Gets or sets the centre of the lens. |
Input | Gets or sets the picture the effect works on. |
Radius | Gets or sets how far the lens reaches from CenterXY. |
| Fields | |
AmountProperty | Identifies the Amount dependency property. |
CenterXYProperty | Identifies the CenterXY dependency property. |
InputProperty | Identifies the Input dependency property. |
RadiusProperty | Identifies the Radius dependency property. |
Constructors
BulgeEffect
Properties
Amount
Gets or sets how strongly the lens distorts the picture, and in which direction.
- Value
- The default is 0.5. Positive values bulge outwards and negative values pinch inwards; 0 leaves the picture unchanged. Values above 1 turn the middle of the lens inside out, so -1 to 1 is the useful range.
CenterXY
Gets or sets the centre of the lens.
- Value
- A point in relative coordinates: (0,0) is the top-left corner of the element and (1,1) its bottom-right. The default is (0.5,0.5), the middle.
Input
Gets or sets the picture the effect works on.
- Value
- A brush. The default is the element the effect is applied to, as WPF renders it – the effect's implicit input.
Remarks
Leave it unset in the usual case, where the effect is set as an element's
Effect. Set it to a
ImageBrush or VisualBrush to
have the effect work on that picture instead.
Radius
Gets or sets how far the lens reaches from CenterXY.
- Value
- A fraction of the element's size; the default is 0.45. Nothing beyond it moves. Values at or below 0 are treated as a tiny lens.
Fields
AmountProperty static
Identifies the Amount dependency property.
CenterXYProperty static
Identifies the CenterXY dependency property.
InputProperty static
Identifies the Input dependency property.
RadiusProperty static
Identifies the Radius dependency property.