dotnet / dotnet/wpf

Proposal: Add support for BorderMode in BlurEffect

Open
#3,151 0 comments 5 reactions 0 assignees View on GitHub
Enhancement Requested
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

## Summary
The proposal is to add support for **`BorderMode`** in **BlurEffect**

This will enable blur effect to be more visually comforting and will enable UI designers to be even more creative.

## Goal
The goal is to add an enum for **`BorderModes`** and a property called **`BorderMode`** in **BlurEffect** class (and internal work that I'm not aware of).

## Rationale
Currently, **BlurEffect** pads extra pixels. Which is good for **UIElements** that are neither clipped nor stretched to fit parent.
But will look ugly when applied to **UIElements** which are either clipped or stretched to fit parent container
See this SO question : [Gaussian blur leads to white frame around image](https://stackoverflow.com/questions/6236054/gaussian-blur-leads-to-white-frame-around-image) to get an insight of my proposal.

**In the image below the element is blurred and has extra padded pixels. It's ok in this case**

![image](https://user-images.githubusercontent.com/63704247/84972230-0e0b5800-b13c-11ea-8fe3-cf1bcc1a9555.png)

**But for cases like this where the element is either stretched to fill or clipped, it will have ugly transparent edges**

![](https://i.stack.imgur.com/vDqBC.png)

So having an option to not pad extra pixel will be helpful in many cases

UWP (Win2D?) has the said property see [GaussianBlurEffect.BorderMode](https://microsoft.github.io/Win2D/html/P_Microsoft_Graphics_Canvas_Effects_GaussianBlurEffect_BorderMode.htm)
and also [Direct2D/GaussianBlur.BorderMode](https://docs.microsoft.com/en-us/windows/win32/direct2d/gaussian-blur#border-modes)

## Proposed API

The same API found in Win2D's GaussianBlurEffect can be used.

```cs
// Enumeration type that specifies how to process pixels that lie outside the input image.
public enum EffectBorderMode
{
// Pixels outside the input image are treated as transparent black, resulting in a soft edge after processing.
Soft = 0, // Default
// The effect clamps to the size of the input image.
Hard = 1
}
```

and in BlurEffect.cs

```cs
// Gets and sets border mode for edge pixels.
public EffectBorderMode BorderMode { get; set; }
```

## Extra Info
_I'm a new comer to WPF and not well introduced to **Open-Source workflow**.
If I there are any mistakes in this proposal, please correct me._

One thing that bothers me is that it's been 13 years since WPF's release and I can't find any issue proposing to change this behavior. **Is it because this can't be implemented or no one asked for it?**

At this point I'm too afraid to ask this, since WPF is on maintenance mode and we are forced towards WinUI for a stable future.
I love WPF and people like me will be so pleased if WPF can be improved with much more features.

## Open questions
- Is this even feasible?
- What will be the difficulty of implementation?
- Is this out of scope?
- Do you devs still plan on adding new features?
- If it the implementation process is feasible, will you consider implementing it?
- Doesn't WPF and UWP both use DirectX for rendering? Then is it possible?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.