usercode / WPF.ImageEffects

GPU-based image effects (brightness, contrast) for WPF
MIT License
12 stars 2 forks source link

Brightness problems with transparent images #4

Open AcruxDevelopment opened 3 weeks ago

AcruxDevelopment commented 3 weeks ago

Problem

I intalled this via dotnet add package WPF.ImageEffects --version 1.5.0 and I found that when I apply the Brightness property to a positive number, the transparent parts of the image get tinted white. However, this does not happen when I apply the property to a negative value or zero.

Notes

I have a single instance of the BrightnessContrastEffect class, where that instance is applied to a Grid full of Images.

The instance is created programmatically:

public BrightnessContrastEffect BrightnessContrastEffect { get; } = new BrightnessContrastEffect();
...
BrightnessContrastEffect.Brightness = 0.5;

And the instance is attached this way: SpriteGrid.Effect = BrightnessContrastEffect;

I am not sure if the problem is related to the fact that the shader also picks up other elements that are not part of the grid itself, but are rendered behind it, thus applying the shader to everything within the grid's boundaries.

Also, having to apply the effects to the images individually isnt a solution for me because it would cause the effect to "accumulate" in semi-transparent images


Thanks for your help.

usercode commented 3 weeks ago

The shader do not touch the alpha value of the pixels.

Maybe the control has a background color which is modified, too?

AcruxDevelopment commented 2 weeks ago

Nop, i created a brand new WPF.NET C# project for testing, just added an image, added the effect to it and the issue persists:

image

image

image

As shown in the image, i selected a random png asset i had, placed it in a gray background colored window (it can be any color, it was just to differenciate between the place where the buggy white tint takes place and the rest of the window), attached the effect, and that's the result.

usercode commented 1 week ago

I'm sure your image doesn't contains full transparent pixels.

If your image contains partial transparent pixels, it will combine the color from the background. That's correct.

Here is an example. The blue rectangle is a full transparent area. (This grid has the blue background color.)

brightness = -1

grafik

brightness = 1

grafik

Please use the example demo from this respository and test again.