HypernovaDesktop Components · docs
Binarymission
WPF › Shaders Library › BulgeEffect

BulgeEffect

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Shaders.Library.CustomEffects

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

PropertyRange and default

Amount

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.

Radius

Reach of the lens from its centre, as a fraction of the element. Default 0.45.

CenterXY

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
BulgeEffectCreates the effect with its default settings: Amount 0.5, Radius 0.45, CenterXY (0.5,0.5).
Properties
AmountGets or sets how strongly the lens distorts the picture, and in which direction.
CenterXYGets or sets the centre of the lens.
InputGets or sets the picture the effect works on.
RadiusGets or sets how far the lens reaches from CenterXY.
Fields
AmountPropertyIdentifies the Amount dependency property.
CenterXYPropertyIdentifies the CenterXY dependency property.
InputPropertyIdentifies the Input dependency property.
RadiusPropertyIdentifies the Radius dependency property.

Constructors

BulgeEffect

public BulgeEffect()

Creates the effect with its default settings: Amount 0.5, Radius 0.45, CenterXY (0.5,0.5).

Properties

Amount

public double 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

public Point 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

public Brush 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

public double 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

public static readonly DependencyProperty AmountProperty

Identifies the Amount dependency property.

CenterXYProperty static

public static readonly DependencyProperty CenterXYProperty

Identifies the CenterXY dependency property.

InputProperty static

public static readonly DependencyProperty InputProperty

Identifies the Input dependency property.

RadiusProperty static

public static readonly DependencyProperty RadiusProperty

Identifies the Radius dependency property.