Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filling with a transparent color does not work as expected #26

Closed
equinox2k opened this issue Jul 24, 2019 · 2 comments
Closed

Filling with a transparent color does not work as expected #26

equinox2k opened this issue Jul 24, 2019 · 2 comments

Comments

@equinox2k
Copy link

Using the following on an existing image to clear it does nothing...

imageToProcess.Mutate(i => i.Fill(SixLabors.ImageSharp.Color.Transparent));

However doing the following works...

var graphicsOptions = new GraphicsOptions
{
    AlphaCompositionMode = PixelAlphaCompositionMode.Clear
};
var rectangle = new RectangleF(0, 0, imageToProcess.Width, imageToProcess.Height);                
imageToProcess.Mutate(i => i.Fill(graphicsOptions, SixLabors.ImageSharp.Color.Transparent, rectangle));

I assume the defaults should of been good enough for the first to work

@JimBobSquarePants JimBobSquarePants transferred this issue from SixLabors/ImageSharp Jan 26, 2020
@arakis
Copy link

arakis commented Apr 5, 2020

Here is a little extension that makes life easier:

public static class ImageExtensions
{
    public static void Clear(this IImageProcessingContext source, Color color)
    {
        var graphicsOptions = new GraphicsOptions
        {
            AlphaCompositionMode = PixelAlphaCompositionMode.Clear
        };
        var size = source.GetCurrentSize();
        source.Fill(graphicsOptions, color, new Rectangle(0, 0, size.Width, size.Height));
    }
}

Just call it:

imageToProcess.Mutate(i => i.Clear(Color.Transparent);

@tocsoft
Copy link
Member

tocsoft commented May 2, 2020

Untill we add our own set of Clear() apis the most efficient way to do this as of now is

public static class ImageExtensions
{
    public static void Clear(this IImageProcessingContext source, Color color)
    {
        var graphicsOptions = new GraphicsOptions
        {
            AlphaCompositionMode = PixelAlphaCompositionMode.Src,
            ColorBlendingMode = PixelColorBlendingMode.Normal
        };
        source.Fill(graphicsOptions, color);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants