Rough anti-aliasing

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
Bert
Posts: 12
Joined: 2018-06-29T05:04:42-07:00
Authentication code: 1152

Rough anti-aliasing

Post by Bert »

Hello

I'm using the following code to put text on a gradient background:

Code: Select all

using ImageMagick;

namespace TextToPicture
{
    class Slideshow
    {
        static void Main(string[] args)
        {
            using (var image = new MagickImage(MagickColors.White, 320, 240))
            {
                image.Density = new Density(300);
                image.Format = MagickFormat.Png;

                using (var gradient = new MagickImage(@"D:\gradient.png", 320, 240))
                    image.Composite(gradient, 0, 0, CompositeOperator.Over);

                using (var completeMask = new MagickImage(MagickColors.Transparent, 310, 30))
                {
                    using (var filledMask = new MagickImage(MagickColors.White, 310, 30))
                        completeMask.Composite(filledMask, 0, 0, CompositeOperator.Over);

                    using (var mText = new MagickImage(MagickColors.Transparent, 310, 30))
                    {
                        var textSettings = new MagickReadSettings
                        {
                            BackgroundColor = MagickColors.Transparent,
                            Width = 310,
                            Height = 30,
                            TextGravity = Gravity.North
                        };

                        mText.Read($"caption:Hello World!", textSettings);

                        using (var completeTextBox = new MagickImage(MagickColors.Transparent, 310, 30))
                        {
                            completeTextBox.Composite(mText, 0, 0, CompositeOperator.Over);
                            completeTextBox.Composite(completeMask, 0, 0);

                            image.Composite(completeTextBox, 5, 60, CompositeOperator.Dissolve, "100");
                        }
                    }
                }
                image.Write(@"D:\test.png");
            }
        }
    }
}
Which yields the following result:
Image

The reason I compose an image over transparent text instead of just applying color to the text is so I can make it fade out to nothing depending on settings, this image composite is normally a gradient. (see my previous post). This is just a simplified example to show my issue.

The issue I'm facing is: The anti-aliasing is very rough because it seems to be using black instead of white as 'color to "anti-aliase"'
Image

Any idea what could cause this?

I'm using Magick.NET v7.6.0 targeting .NET Framework 4.6.1 .

The image gradient I've used (D:\gradient.png) is provided below.
Image

Thanks.
Bert
Posts: 12
Joined: 2018-06-29T05:04:42-07:00
Authentication code: 1152

Re: Rough anti-aliasing

Post by Bert »

-snip-

I thought I solved the issue, but I just put Dissolve to zero (which just removes the 'overlay'), so that's not the way to go.
Bert
Posts: 12
Joined: 2018-06-29T05:04:42-07:00
Authentication code: 1152

Re: Rough anti-aliasing

Post by Bert »

And now I have solved the issue, heh...

I've changed

Code: Select all

completeTextBox.Composite(completeMask, 0, 0);
to

Code: Select all

completeTextBox.Composite(completeMask, 0, 0, CompositeOperator.Multiply);
Which is logical, when you think about it but I didn't make the connection that opacity might get screwed up when using composites.
Post Reply